diff --git a/sunshine/main.cpp b/sunshine/main.cpp index a24b562e..801493aa 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -154,6 +154,8 @@ int main(int argc, char *argv[]) { stream::rtpThread(shutdown_event); httpThread.join(); + task_pool.stop(); + task_pool.join(); return 0; } diff --git a/sunshine/nvhttp.cpp b/sunshine/nvhttp.cpp index da402706..98f5a79d 100644 --- a/sunshine/nvhttp.cpp +++ b/sunshine/nvhttp.cpp @@ -846,8 +846,22 @@ void start(std::shared_ptr 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();