]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Get rid of the weird delayed tasks during configuration/startup
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 11 Jun 2024 12:54:16 +0000 (14:54 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2024 09:47:55 +0000 (11:47 +0200)
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-lua.hh
pdns/dnsdistdist/dnsdist.cc

index c0da1259e2374b9d6e3f959d1df10abce0ac6aca..8d05c3137ece14363c058d3cc30a95f7d24ff10c 100644 (file)
@@ -82,8 +82,6 @@
 
 using std::thread;
 
-static std::optional<std::vector<std::function<void(void)>>> s_launchWork{std::nullopt};
-
 static boost::tribool s_noLuaSideEffect;
 
 /* this is a best effort way to prevent logging calls with no side-effects in the output of delta()
@@ -699,12 +697,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
                          }
 
                          if (ret->connected) {
-                           if (s_launchWork) {
-                             s_launchWork->push_back([ret]() {
-                               ret->start();
-                             });
-                           }
-                           else {
+                           if (!dnsdist::configuration::isConfigurationDone()) {
                              ret->start();
                            }
                          }
@@ -3367,12 +3360,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
   });
 }
 
-vector<std::function<void(void)>> setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config)
+void setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config)
 {
-  // this needs to exist only during the parsing of the configuration
-  // and cannot be captured by lambdas
-  s_launchWork = std::vector<std::function<void(void)>>();
-
   setupLuaActions(luaCtx);
   setupLuaConfig(luaCtx, client, configCheck);
   setupLuaBindings(luaCtx, client, configCheck);
@@ -3407,9 +3396,4 @@ vector<std::function<void(void)>> setupLua(LuaContext& luaCtx, bool client, bool
   }
 
   luaCtx.executeCode(ifs);
-
-  auto ret = std::move(*s_launchWork);
-  s_launchWork = std::nullopt;
-
-  return ret;
 }
index 475d0570c7470772d18c3c82fc7075c00a92a601..441939999e26e445dd1cd4739411373a2e35a7dc 100644 (file)
@@ -170,7 +170,7 @@ std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var, const std::string& ca
 void parseRuleParams(boost::optional<luaruleparams_t>& params, boost::uuids::uuid& uuid, std::string& name, uint64_t& creationOrder);
 void checkParameterBound(const std::string& parameter, uint64_t value, size_t max = std::numeric_limits<uint16_t>::max());
 
-std::vector<std::function<void(void)>> setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config);
+void setupLua(LuaContext& luaCtx, bool client, bool configCheck, const std::string& config);
 void setupLuaActions(LuaContext& luaCtx);
 void setupLuaBindings(LuaContext& luaCtx, bool client, bool configCheck);
 void setupLuaBindingsDNSCrypt(LuaContext& luaCtx, bool client);
index 3eb1360d63ca4dbb81c5af0f0cf2535e63232901..489553b08dcc5ad2f4584f9b2f4cd9821876f431 100644 (file)
@@ -3378,7 +3378,7 @@ int main(int argc, char** argv)
 
     dnsdist::g_asyncHolder = std::make_unique<dnsdist::AsynchronousHolder>();
 
-    auto todo = setupLua(*(g_lua.lock()), false, false, cmdLine.config);
+    setupLua(*(g_lua.lock()), false, false, cmdLine.config);
 
     setupPools();
 
@@ -3481,12 +3481,15 @@ int main(int argc, char** argv)
       webServerThread.detach();
     }
 
-    for (auto& todoItem : todo) {
-      todoItem();
-    }
-
     /* create the default pool no matter what */
     createPoolIfNotExists("");
+
+    for (auto& backend : dnsdist::configuration::getCurrentRuntimeConfiguration().d_backends) {
+      if (backend->connected) {
+        backend->start();
+      }
+    }
+
     if (!cmdLine.remotes.empty()) {
       for (const auto& address : cmdLine.remotes) {
         DownstreamState::Config config;