Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions pdns/auth-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,26 @@ static void triggerLoadOfLibraries()
dummy.join();
}

static bool updateZoneCache(Logr::log_t slog)
{
try {
UeberBackend B; // NOLINT(readability-identifier-length)
B.updateZoneCache();
}
catch (PDNSException& e) {
SLOG(g_log << Logger::Error << "PDNSException while filling the zone cache: " << e.reason << endl,
slog->error(Logr::Error, e.reason, "PDNSException while filling the zone cache"));
return false;
}
catch (std::exception& e) {
SLOG(g_log << Logger::Error << "STL Exception while filling the zone cache: " << e.what() << endl,
slog->error(Logr::Error, e.what(), "STL Exception while filling the zone cache"));
return false;
}
return true;
}

// NOLINTNEXTLINE(readability-function-cognitive-complexity)
static void mainthread()
{
static std::shared_ptr<Logr::Logger> slog;
Expand Down Expand Up @@ -967,19 +987,10 @@ static void mainthread()

// Setup the zone cache
g_zoneCache.setRefreshInterval(::arg().asNum("zone-cache-refresh-interval"));
try {
UeberBackend B;
B.updateZoneCache();
}
catch (PDNSException& e) {
SLOG(g_log << Logger::Error << "PDNSException while filling the zone cache: " << e.reason << endl,
slog->error(Logr::Error, e.reason, "PDNSException while filling the zone cache"));
exit(1);
}
catch (std::exception& e) {
SLOG(g_log << Logger::Error << "STL Exception while filling the zone cache: " << e.what() << endl,
slog->error(Logr::Error, e.what(), "STL Exception while filling the zone cache"));
exit(1);
if (g_zoneCache.getRefreshInterval() != 0) {
if (!updateZoneCache(slog)) {
exit(1); // NOLINT(concurrency-mt-unsafe) we're single threaded at this point
}
}

// NOW SAFE TO CREATE THREADS!
Expand Down Expand Up @@ -1016,23 +1027,16 @@ static void mainthread()
uint32_t secpollSince = 0;
uint32_t zoneCacheUpdateSince = 0;
for (;;) {
const uint32_t sleeptime = g_zoneCache.getRefreshInterval() == 0 ? secpollInterval : std::min(secpollInterval, g_zoneCache.getRefreshInterval());
auto zoneCacheRefresh = g_zoneCache.getRefreshInterval();
const uint32_t sleeptime = zoneCacheRefresh == 0 ? secpollInterval : std::min(secpollInterval, zoneCacheRefresh);
sleep(sleeptime); // if any signals arrive, we might run more often than expected.

zoneCacheUpdateSince += sleeptime;
if (zoneCacheUpdateSince >= g_zoneCache.getRefreshInterval()) {
try {
UeberBackend B;
B.updateZoneCache();
zoneCacheUpdateSince = 0;
}
catch (PDNSException& e) {
SLOG(g_log << Logger::Error << "PDNSException while updating zone cache: " << e.reason << endl,
slog->error(Logr::Error, e.reason, "PDNSException while updating the zone cache"));
}
catch (std::exception& e) {
SLOG(g_log << Logger::Error << "STL Exception while updating zone cache: " << e.what() << endl,
slog->error(Logr::Error, e.what(), "STL Exception while updating the zone cache"));
if (zoneCacheRefresh != 0) {
zoneCacheUpdateSince += sleeptime;
if (zoneCacheUpdateSince >= zoneCacheRefresh) {
if (updateZoneCache(slog)) {
zoneCacheUpdateSince = 0;
}
}
}

Expand Down
Loading