From 8657c2af898ca06a484856091e975e0e4f58d512 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 11 Nov 2019 12:34:56 +0100 Subject: [PATCH] Make threads run until asked to stop. This is safer since the atexit handler is not ran while threads are still active. Also, when using valgrind we get more clean leak reports. Retry if the accidentally merged #8518 that was reverted. --- pdns/pdns_recursor.cc | 10 ++++++++-- pdns/rec_channel.cc | 2 ++ pdns/rec_channel.hh | 2 ++ pdns/rec_channel_rec.cc | 11 ++++++----- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d36625e4d9..c6200a1e5f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4279,6 +4279,8 @@ static int serviceMain(int argc, char*argv[]) infos.isListener = true; infos.isWorker = true; recursorThread(currentThreadId++, "worker"); + + handlerInfos.thread.join(); } else { @@ -4313,7 +4315,9 @@ static int serviceMain(int argc, char*argv[]) infos.isHandler = true; infos.thread = std::thread(recursorThread, 0, "web+stat"); - s_threadInfos.at(0).thread.join(); + for (auto & ti : s_threadInfos) { + ti.thread.join(); + } } return 0; } @@ -4448,7 +4452,8 @@ try time_t carbonInterval=::arg().asNum("carbon-interval"); time_t luaMaintenanceInterval=::arg().asNum("lua-maintenance-interval"); counter.store(0); // used to periodically execute certain tasks - for(;;) { + + while (!RecursorControlChannel::stop) { while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing if(!(counter%500)) { @@ -4516,6 +4521,7 @@ try } } } + return 0; } catch(PDNSException &ae) { g_log< #include #include +#include #include #include "iputils.hh" #include "dnsname.hh" @@ -53,6 +54,7 @@ public: std::string recv(std::string* remote=0, unsigned int timeout=5); int d_fd; + static volatile sig_atomic_t stop; private: struct sockaddr_un d_local; }; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index a86500ba12..a294e62ac7 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1165,15 +1165,16 @@ void doExitGeneric(bool nicely) { g_log<