From ce715f38fcedf752220cd5056e1a3945330041fd Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 3 Dec 2020 09:34:08 +0100 Subject: [PATCH] rec: Handle failure to start the web server more gracefully At this point we already have several threads so calling exit() will cause problem by trying to destruct objects that are in use by other threads, so call _exit() instead. Also mention the web server in the error message so that the root cause is easier to identify. --- pdns/pdns_recursor.cc | 14 +++++++------- pdns/ws-recursor.cc | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f3a5d17d68..6c9e641e97 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -3658,7 +3658,7 @@ static bool trySendingQueryToWorker(unsigned int target, ThreadMSG* tmsg) auto& targetInfo = s_threadInfos[target]; if(!targetInfo.isWorker) { g_log< T broadcastAccFunction(const boost::function& func) { if (!isHandlerThread()) { g_log<getName() << "' multiplexer"<(new AsyncWebServer(fdm, arg()["webserver-address"], arg().asNum("webserver-port"))); + d_ws = make_unique(fdm, arg()["webserver-address"], arg().asNum("webserver-port")); + d_ws->setApiKey(arg()["api-key"]); d_ws->setPassword(arg()["webserver-password"]); d_ws->setLogLevel(arg()["webserver-loglevel"]); @@ -534,8 +535,10 @@ RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm) d_ws->registerApiHandler("/api/v1/servers", &apiServer); d_ws->registerApiHandler("/api", &apiDiscovery); - for(const auto& u : g_urlmap) + for (const auto& u : g_urlmap) { d_ws->registerWebHandler("/"+u.first, serveStuff); + } + d_ws->registerWebHandler("/", serveStuff); d_ws->registerWebHandler("/metrics", prometheusMetrics); d_ws->go(); -- 2.47.2