From b441c2fd41feb48a1c27b7faf89babc4ab11977c Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 28 Mar 2022 13:53:14 +0200 Subject: [PATCH] In the handler, call sd_notify just befere entering the main loop in RecursorThread There still is a race, but this is better than calling sd_notify before the handler is created. --- pdns/recursordist/rec-main.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index dc9b1f3e85..7f80028a1f 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -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 -- 2.47.2