Fix crash when sending SIGINT before starting the http server
This commit is contained in:
@@ -154,6 +154,8 @@ int main(int argc, char *argv[]) {
|
|||||||
stream::rtpThread(shutdown_event);
|
stream::rtpThread(shutdown_event);
|
||||||
|
|
||||||
httpThread.join();
|
httpThread.join();
|
||||||
|
task_pool.stop();
|
||||||
|
task_pool.join();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-2
@@ -846,8 +846,22 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread ssl { &https_server_t::accept_and_run, &https_server };
|
auto accept_and_run = [&](auto *http_server) {
|
||||||
std::thread tcp { &http_server_t::accept_and_run, &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
|
// Wait for any event
|
||||||
shutdown_event->view();
|
shutdown_event->view();
|
||||||
|
|||||||
Reference in New Issue
Block a user