]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Create TCP worker threads before acceptors ones 10088/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 16 Feb 2021 10:43:40 +0000 (11:43 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 16 Feb 2021 10:43:40 +0000 (11:43 +0100)
Otherwise we might crash when the first TCP query arrives because
we are dividing by zero when trying to select a worker.

pdns/dnsdist.cc
pdns/dnsdist.hh

index d6c6aa9ac58455aad867ba6b79becc5437bf44bd..bf68654f2c0359cabe0c292f2a3e21f8860a77ef 100644 (file)
@@ -2418,6 +2418,13 @@ int main(int argc, char** argv)
     }
     handleQueuedHealthChecks(mplexer, true);
 
+    /* we need to create the TCP worker threads before the
+       acceptor ones, otherwise we might crash when processing
+       the first TCP query */
+    while (!g_tcpclientthreads->hasReachedMaxThreads()) {
+      g_tcpclientthreads->addTCPClientThread();
+    }
+
     for(auto& cs : g_frontends) {
       if (cs->dohFrontend != nullptr) {
 #ifdef HAVE_DNS_OVER_HTTPS
@@ -2445,10 +2452,6 @@ int main(int argc, char** argv)
       }
     }
 
-    while (!g_tcpclientthreads->hasReachedMaxThreads()) {
-      g_tcpclientthreads->addTCPClientThread();
-    }
-
     thread carbonthread(carbonDumpThread);
     carbonthread.detach();
 
index d93340a3713af16cf9c1a29134c17b108b78586a..a98c7324d3732fc383a83576f041772a594606ef 100644 (file)
@@ -857,6 +857,10 @@ public:
   }
   int getThread()
   {
+    if (d_numthreads == 0) {
+      throw std::runtime_error("No TCP worker thread yet");
+    }
+
     uint64_t pos = d_pos++;
     ++d_queued;
     return d_tcpclientthreads.at(pos % d_numthreads);