From: Otto Moerbeek Date: Mon, 22 Jan 2024 14:13:35 +0000 (+0100) Subject: Rate limit the notifies per zone to max 1 per 5 sec (less if refresh is lower) X-Git-Tag: dnsdist-1.9.0-rc1~15^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c33b0247c08a370a508f26494507af054ce2bb10;p=thirdparty%2Fpdns.git Rate limit the notifies per zone to max 1 per 5 sec (less if refresh is lower) --- diff --git a/pdns/recursordist/rpzloader.cc b/pdns/recursordist/rpzloader.cc index f04f9ce302..5eb5f315d7 100644 --- a/pdns/recursordist/rpzloader.cc +++ b/pdns/recursordist/rpzloader.cc @@ -479,10 +479,20 @@ static bool RPZTrackerIteration(RPZTrackerParams& params, const DNSName& zoneNam skipRefreshDelay = false; } else { - std::unique_lock lock(rpzwaiter.mutex); - rpzwaiter.condVar.wait_for(lock, std::chrono::seconds(refresh), - [&stop = rpzwaiter.stop] { return stop.load(); }); - rpzwaiter.stop = false; + const time_t minimumTimeBetweenRefreshes = std::min(refresh, 5U); + const time_t startTime = time(nullptr); + time_t wakeTime = startTime; + while (wakeTime - startTime < minimumTimeBetweenRefreshes) { + std::unique_lock lock(rpzwaiter.mutex); + time_t remaining = refresh - (wakeTime - startTime); + if (remaining <= 0) { + break; + } + rpzwaiter.condVar.wait_for(lock, std::chrono::seconds(remaining), + [&stop = rpzwaiter.stop] { return stop.load(); }); + rpzwaiter.stop = false; + wakeTime = time(nullptr); + } } auto luaconfsLocal = g_luaconfs.getLocal(); @@ -701,10 +711,9 @@ void RPZIXFRTracker(RPZTrackerParams params, uint64_t configGeneration) auto [start, end] = lock->equal_range(zoneName); while (start != end) { if (start->second.id == std::this_thread::get_id()) { - start = lock->erase(start); - } - else { - ++start; + lock->erase(start); + break; } + ++start; } }