]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Handle failure to start the web server more gracefully 9812/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 3 Dec 2020 08:34:08 +0000 (09:34 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 3 Dec 2020 08:34:08 +0000 (09:34 +0100)
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
pdns/ws-recursor.cc

index f3a5d17d68b4f4c1a2a5e959c33f1c3a888d8935..6c9e641e97742ceb6b58787dc523e6ab0ee71698 100644 (file)
@@ -3658,7 +3658,7 @@ static bool trySendingQueryToWorker(unsigned int target, ThreadMSG* tmsg)
   auto& targetInfo = s_threadInfos[target];
   if(!targetInfo.isWorker) {
     g_log<<Logger::Error<<"distributeAsyncFunction() tried to assign a query to a non-worker thread"<<endl;
-    exit(1);
+    _exit(1);
   }
 
   const auto& tps = targetInfo.pipes;
@@ -3731,7 +3731,7 @@ void distributeAsyncFunction(const string& packet, const pipefunc_t& func)
 {
   if (!isDistributorThread()) {
     g_log<<Logger::Error<<"distributeAsyncFunction() has been called by a worker ("<<t_id<<")"<<endl;
-    exit(1);
+    _exit(1);
   }
 
   unsigned int hash = hashQuestion(packet.c_str(), packet.length(), g_disthashseed);
@@ -3813,7 +3813,7 @@ template<class T> T broadcastAccFunction(const boost::function<T*()>& func)
 {
   if (!isHandlerThread()) {
     g_log<<Logger::Error<<"broadcastAccFunction has been called by a worker ("<<t_id<<")"<<endl;
-    exit(1);
+    _exit(1);
   }
 
   unsigned int n = 0;
@@ -4068,7 +4068,7 @@ static FDMultiplexer* getMultiplexer()
     }
   }
   g_log<<Logger::Error<<"No working multiplexer found!"<<endl;
-  exit(1);
+  _exit(1);
 }
 
 
@@ -5086,9 +5086,9 @@ try
       try {
         rws = new RecursorWebServer(t_fdm);
       }
-      catch(PDNSException &e) {
-        g_log<<Logger::Error<<"Exception: "<<e.reason<<endl;
-        exit(99);
+      catch (const PDNSException &e) {
+        g_log<<Logger::Error<<"Unable to start the internal web server: "<<e.reason<<endl;
+        _exit(99);
       }
     }
     g_log<<Logger::Info<<"Enabled '"<< t_fdm->getName() << "' multiplexer"<<endl;
index d80b6897772c11283b3a49598f6c56ea0dc0f347..1c31c1f7face0294161b714a4bd46c07c7f8d076 100644 (file)
@@ -509,7 +509,8 @@ RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm)
 {
   registerAllStats();
 
-  d_ws = std::unique_ptr<AsyncWebServer>(new AsyncWebServer(fdm, arg()["webserver-address"], arg().asNum("webserver-port")));
+  d_ws = make_unique<AsyncWebServer>(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();