]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
In the handler, call sd_notify just befere entering the main loop in RecursorThread 11471/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 28 Mar 2022 11:53:14 +0000 (13:53 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 28 Mar 2022 11:55:23 +0000 (13:55 +0200)
There still is a race, but this is better than calling sd_notify before the handler is created.

pdns/recursordist/rec-main.cc

index dc9b1f3e85019925108955e35c9482b57155e946..7f80028a1f2c1b9906bea1a794b14c7609f4a15c 100644 (file)
@@ -200,10 +200,6 @@ int RecThreadInfo::runThreads()
   if (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers() == 1) {
     g_log << Logger::Warning << "Operating with single distributor/worker thread" << endl;
 
-#ifdef HAVE_SYSTEMD
-    sd_notify(0, "READY=1");
-#endif
-
     /* This thread handles the web server, carbon, statistics and the control channel */
     auto& handlerInfo = RecThreadInfo::info(0);
     handlerInfo.setHandler();
@@ -266,10 +262,6 @@ int RecThreadInfo::runThreads()
       info.start(currentThreadId++, "taskThread", cpusMap);
     }
 
-#ifdef HAVE_SYSTEMD
-    sd_notify(0, "READY=1");
-#endif
-
     /* This thread handles the web server, carbon, statistics and the control channel */
     auto& info = RecThreadInfo::info(0);
     info.setHandler();
@@ -2178,6 +2170,15 @@ static void recursorThread()
     time_t luaMaintenanceInterval = ::arg().asNum("lua-maintenance-interval");
     s_counter.store(0); // used to periodically execute certain tasks
 
+#ifdef HAVE_SYSTEMD
+    if (threadInfo.isHandler()) {
+      // There is a race, as some threads might not be ready yet to do work.
+      // To solve that, threads should notify RecThreadInfo they are done initializing.
+      // But we lack a mechanism for that at this point in time.
+      sd_notify(0, "READY=1");
+    }
+#endif
+
     while (!RecursorControlChannel::stop) {
       while (MT->schedule(&g_now))
         ; // MTasker letting the mthreads do their thing