Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursor not responsive after Lua config reload #11850

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdns/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ void startDoResolve(void* p)
sr.setInitialRequestId(dc->d_uuid);
sr.setOutgoingProtobufServers(t_outgoingProtobufServers);
#ifdef HAVE_FSTRM
sr.setFrameStreamServers(t_frameStreamServers);
sr.setFrameStreamServers(t_frameStreamServersInfo.servers);
#endif

bool useMapped = true;
Expand Down
21 changes: 21 additions & 0 deletions pdns/rec-lua-conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ LuaConfigItems::LuaConfigItems()

/* DID YOU READ THE STORY ABOVE? */

bool operator==(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB)
{
// clang-format off
return configA.enabled == configB.enabled &&
configA.logQueries == configB.logQueries &&
configA.logResponses == configB.logResponses &&
configA.bufferHint == configB.bufferHint &&
configA.flushTimeout == configB.flushTimeout &&
configA.inputQueueSize == configB.inputQueueSize &&
configA.outputQueueSize == configB.outputQueueSize &&
configA.queueNotifyThreshold == configB.queueNotifyThreshold &&
configA.reopenInterval == configB.reopenInterval &&
configA.servers == configB.servers;
// clang-format on
}

bool operator!=(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB)
{
return !(configA == configB);
}

template <typename C>
typename C::value_type::second_type constGet(const C& c, const std::string& name)
{
Expand Down
4 changes: 4 additions & 0 deletions pdns/rec-lua-conf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "validate.hh"
#include "rec-zonetocache.hh"
#include "logging.hh"
#include "fstrm_logger.hh"

struct ProtobufExportConfig
{
Expand Down Expand Up @@ -58,6 +59,9 @@ struct FrameStreamExportConfig
unsigned reopenInterval{0};
};

bool operator==(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB);
bool operator!=(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB);

struct TrustAnchorFileInfo
{
uint32_t interval{24};
Expand Down
35 changes: 22 additions & 13 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ static thread_local uint64_t t_protobufServersGeneration;
static thread_local uint64_t t_outgoingProtobufServersGeneration;

#ifdef HAVE_FSTRM
thread_local std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> t_frameStreamServers{nullptr};
thread_local uint64_t t_frameStreamServersGeneration;
thread_local FrameStreamServersInfo t_frameStreamServersInfo;
#endif /* HAVE_FSTRM */

string g_programname = "pdns_recursor";
Expand Down Expand Up @@ -626,29 +625,39 @@ static std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> startFra
return result;
}

static void asyncFrameStreamLoggersCleanup(std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>>&& servers)
{
auto thread = std::thread([&] {
servers.reset();
});
thread.detach();
}

bool checkFrameStreamExport(LocalStateHolder<LuaConfigItems>& luaconfsLocal)
{
if (!luaconfsLocal->frameStreamExportConfig.enabled) {
if (t_frameStreamServers) {
if (t_frameStreamServersInfo.servers) {
// dt's take care of cleanup
t_frameStreamServers.reset();
asyncFrameStreamLoggersCleanup(std::move(t_frameStreamServersInfo.servers));
fredmorcos marked this conversation as resolved.
Show resolved Hide resolved
t_frameStreamServersInfo.config = luaconfsLocal->frameStreamExportConfig;
}

return false;
}

/* if the server was not running, or if it was running according to a
previous configuration */
if (!t_frameStreamServers || t_frameStreamServersGeneration < luaconfsLocal->generation) {

if (t_frameStreamServers) {
/* if the server was not running, or if it was running according to a previous
* configuration
*/
if (t_frameStreamServersInfo.generation < luaconfsLocal->generation && t_frameStreamServersInfo.config != luaconfsLocal->frameStreamExportConfig) {
if (t_frameStreamServersInfo.servers) {
// dt's take care of cleanup
t_frameStreamServers.reset();
asyncFrameStreamLoggersCleanup(std::move(t_frameStreamServersInfo.servers));
}

auto log = g_slog->withName("dnstap");
t_frameStreamServers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig, log);
t_frameStreamServersGeneration = luaconfsLocal->generation;
auto dnsTapLog = g_slog->withName("dnstap");
t_frameStreamServersInfo.servers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig, dnsTapLog);
t_frameStreamServersInfo.config = luaconfsLocal->frameStreamExportConfig;
t_frameStreamServersInfo.generation = luaconfsLocal->generation;
}

return true;
Expand Down
10 changes: 8 additions & 2 deletions pdns/recursordist/rec-main.hh
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,14 @@ extern thread_local std::shared_ptr<nod::UniqueResponseDB> t_udrDBp;
#endif

#ifdef HAVE_FSTRM
extern thread_local std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> t_frameStreamServers;
extern thread_local uint64_t t_frameStreamServersGeneration;
struct FrameStreamServersInfo
{
std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> servers;
uint64_t generation;
FrameStreamExportConfig config;
};

extern thread_local FrameStreamServersInfo t_frameStreamServersInfo;
#endif /* HAVE_FSTRM */

#ifdef HAVE_BOOST_CONTAINER_FLAT_SET_HPP
Expand Down