Skip to content

Commit

Permalink
dnsdist: Get rid of the weird delayed tasks during configuration/startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Jul 5, 2024
1 parent 4f3bd69 commit 9490b67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
20 changes: 2 additions & 18 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -3365,12 +3358,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);
Expand Down Expand Up @@ -3404,9 +3393,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;
}
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions pdns/dnsdistdist/dnsdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9490b67

Please sign in to comment.