From 9490b670984fb57fa5225a977be794883cf294a6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 11 Jun 2024 14:54:16 +0200 Subject: [PATCH] dnsdist: Get rid of the weird delayed tasks during configuration/startup --- pdns/dnsdistdist/dnsdist-lua.cc | 20 ++------------------ pdns/dnsdistdist/dnsdist-lua.hh | 2 +- pdns/dnsdistdist/dnsdist.cc | 13 ++++++++----- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 52a1b44d828c..c4e3ac95f6a7 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -82,8 +82,6 @@ using std::thread; -static std::optional>> 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(); } } @@ -3365,12 +3358,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) }); } -vector> 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>(); - setupLuaActions(luaCtx); setupLuaConfig(luaCtx, client, configCheck); setupLuaBindings(luaCtx, client, configCheck); @@ -3404,9 +3393,4 @@ vector> setupLua(LuaContext& luaCtx, bool client, bool } luaCtx.executeCode(ifs); - - auto ret = std::move(*s_launchWork); - s_launchWork = std::nullopt; - - return ret; } diff --git a/pdns/dnsdistdist/dnsdist-lua.hh b/pdns/dnsdistdist/dnsdist-lua.hh index 48d3ed2df59d..dd5ee053a9f3 100644 --- a/pdns/dnsdistdist/dnsdist-lua.hh +++ b/pdns/dnsdistdist/dnsdist-lua.hh @@ -170,7 +170,7 @@ std::shared_ptr makeRule(const luadnsrule_t& var, const std::string& ca void parseRuleParams(boost::optional& 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::max()); -std::vector> 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); diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 56b4472ad1fc..09bd364f88aa 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -3378,7 +3378,7 @@ int main(int argc, char** argv) dnsdist::g_asyncHolder = std::make_unique(); - 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;