deadlock on main thread with CS
this scenario is complicated but it occurs when a command which creates a CS is run on both http listener and main thread io service.
when the command is run on the http threads, the checkCallbacksPermissions throws, but when it is run on main thread it continues taking the CS lock. after the lock is acquired, main threads are stopped and http listener is stopped. this continues with the following code:
void
HttpThreadPool::setState(State state) {
...
case State::PAUSED: {
// Stop IOService.
if (!io_service_->stopped()) {
io_service_->poll();
io_service_->stop();
}
...
the issue comes from the fact that the http listener thread has commands queued which also create a CS and by calling io_service_->poll(), the CS is entered again on the main thread causing deadlock.