Fix crash when sending SIGINT before starting the http server
This commit is contained in:
parent
88c3828ad3
commit
a93bad4cf3
2 changed files with 18 additions and 2 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue