From 3cd61b1af7f755ad13f6d0151ad6c2445e26b9bf Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Wed, 13 May 2026 08:02:57 +0200 Subject: [PATCH 1/3] Skip zone cache refresh logic if disabled. Signed-off-by: Miod Vallat --- pdns/auth-main.cc | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 4084740ecc65..719e8f00853d 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -967,19 +967,21 @@ 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) { + 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); + } } // NOW SAFE TO CREATE THREADS! @@ -1016,23 +1018,26 @@ 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) { + 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")); + } } } From 9818c4db861f617f725f11c6f3d01dc5095fb0f2 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Wed, 13 May 2026 12:55:38 +0200 Subject: [PATCH 2/3] Factor some code to reduce clang-tidy cognitive-complexity. Signed-off-by: Miod Vallat --- pdns/auth-main.cc | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 719e8f00853d..30ee672a8243 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -757,6 +757,25 @@ static void triggerLoadOfLibraries() dummy.join(); } +static bool updateZoneCache(Logr::log_t slog) +{ + 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")); + 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; +} + static void mainthread() { static std::shared_ptr slog; @@ -968,18 +987,7 @@ static void mainthread() // Setup the zone cache g_zoneCache.setRefreshInterval(::arg().asNum("zone-cache-refresh-interval")); if (g_zoneCache.getRefreshInterval() != 0) { - 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")); + if (!updateZoneCache(slog)) { exit(1); } } @@ -1025,19 +1033,9 @@ static void mainthread() if (zoneCacheRefresh != 0) { zoneCacheUpdateSince += sleeptime; if (zoneCacheUpdateSince >= zoneCacheRefresh) { - try { - UeberBackend B; - B.updateZoneCache(); + if (updateZoneCache(slog)) { 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")); - } } } From f77f81429e938359a8a7b0dc7bc484e91eef8106 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Wed, 13 May 2026 15:32:47 +0200 Subject: [PATCH 3/3] clang-tidy gets in the way. Signed-off-by: Miod Vallat --- pdns/auth-main.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 30ee672a8243..925d917b71dc 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -760,7 +760,7 @@ static void triggerLoadOfLibraries() static bool updateZoneCache(Logr::log_t slog) { try { - UeberBackend B; + UeberBackend B; // NOLINT(readability-identifier-length) B.updateZoneCache(); } catch (PDNSException& e) { @@ -776,6 +776,7 @@ static bool updateZoneCache(Logr::log_t slog) return true; } +// NOLINTNEXTLINE(readability-function-cognitive-complexity) static void mainthread() { static std::shared_ptr slog; @@ -988,7 +989,7 @@ static void mainthread() g_zoneCache.setRefreshInterval(::arg().asNum("zone-cache-refresh-interval")); if (g_zoneCache.getRefreshInterval() != 0) { if (!updateZoneCache(slog)) { - exit(1); + exit(1); // NOLINT(concurrency-mt-unsafe) we're single threaded at this point } }