Fix crash when sending SIGINT before starting the http server

This commit is contained in:
loki 2021-05-05 15:53:22 +02:00
parent 88c3828ad3
commit a93bad4cf3
2 changed files with 18 additions and 2 deletions

View File

@ -154,6 +154,8 @@ int main(int argc, char *argv[]) {
stream::rtpThread(shutdown_event);
httpThread.join();
task_pool.stop();
task_pool.join();
return 0;
}

View File

@ -846,8 +846,22 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
return;
}
std::thread ssl { &https_server_t::accept_and_run, &https_server };
std::thread tcp { &http_server_t::accept_and_run, &http_server };
auto accept_and_run = [&](auto *http_server) {
try {
http_server->accept_and_run();
} catch(boost::system::system_error &err) {
// It's possible the exception gets thrown after calling http_server->stop() from a different thread
if(shutdown_event->peek()) {
return;
}
BOOST_LOG(fatal) << "Couldn't start http server to ports ["sv << PORT_HTTPS << ", "sv << PORT_HTTP << "]: "sv << err.what();
shutdown_event->raise(true);
return;
}
};
std::thread ssl { accept_and_run, &https_server };
std::thread tcp { accept_and_run, &http_server };
// Wait for any event
shutdown_event->view();