]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Rate limit the notifies per zone to max 1 per 5 sec (less if refresh is lower)
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 22 Jan 2024 14:13:35 +0000 (15:13 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 22 Jan 2024 14:16:34 +0000 (15:16 +0100)
pdns/recursordist/rpzloader.cc

index f04f9ce3029231437b1b4f5cd48d7518f2db21ca..5eb5f315d7c7eecbc4cf23b14ea6c939dec596da 100644 (file)
@@ -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;
   }
 }