diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 95a12008..f2ce3b56 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -70,8 +70,16 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server) event_system::instance().start(); - static auto *this_server{server_}; - static const auto quit_handler = [](int /* sig */) { this_server->stop(); }; + static std::atomic this_server{server_}; + static const auto quit_handler = [](int /* sig */) { + auto *ptr = this_server.load(); + if (ptr == nullptr) { + return; + } + + this_server = nullptr; + ptr->stop(); + }; std::signal(SIGINT, quit_handler); #if !defined(_WIN32) @@ -80,6 +88,7 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server) std::signal(SIGTERM, quit_handler); server_->listen("127.0.0.1", config_->get_api_port()); + this_server = nullptr; } handlers::~handlers() { event_system::instance().stop(); }