]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Do not keep stale cache entries around for empty pools 16721/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 13 Jan 2026 15:25:10 +0000 (16:25 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 13 Jan 2026 15:25:10 +0000 (16:25 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-backend.cc
pdns/dnsdistdist/dnsdist-server-pool.hh
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/test-dnsdistserverpool.cc

index 112655401c6f3ce6648c2ffbb4602397e78118e7..a755f5be417652cfc048f0723c0348a88950c459 100644 (file)
@@ -1152,6 +1152,11 @@ void ServerPool::setECS(bool useECS)
   updateConsistency();
 }
 
+bool ServerPool::shouldKeepStaleData() const
+{
+  return !getServers().empty() && countServers(true) == 0;
+}
+
 namespace dnsdist::backend
 {
 void registerNewBackend(std::shared_ptr<DownstreamState>& backend)
index 78ba591aa90643410e4166a6f33163e17c2e0c78..9aa6d533febaa6d762637a86d331267b27b0b47e 100644 (file)
@@ -64,6 +64,7 @@ struct ServerPool
   size_t poolLoad() const;
   size_t countServers(bool upOnly) const;
   bool hasAtLeastOneServerAvailable() const;
+  bool shouldKeepStaleData() const;
   const ServerPolicy::NumberedServerVector& getServers() const;
   void addServer(std::shared_ptr<DownstreamState>& server);
   void removeServer(std::shared_ptr<DownstreamState>& server);
index a4bebd84e4ab7b345fff1a4d34a3e10a0e4a94c2..200f4d3d4bb4a6c620ea428a9310e348a1646d2d 100644 (file)
@@ -2426,7 +2426,7 @@ static void maintThread()
            has all its backends down) */
         if (packetCache->keepStaleData() && !iter->second) {
           /* so far all pools had at least one backend up */
-          if (pool.countServers(true) == 0) {
+          if (pool.shouldKeepStaleData()) {
             iter->second = true;
           }
         }
index f9370adacf2d29ff0c88b339d9f282f3e6790df7..d15a43aa77c143e6f091b7ac2ce88a71f338199b 100644 (file)
@@ -59,6 +59,7 @@ BOOST_AUTO_TEST_CASE(test_ServerPoolBasics)
   BOOST_CHECK_EQUAL(pool.countServers(true), 0U);
   BOOST_CHECK_EQUAL(pool.countServers(false), 0U);
   BOOST_CHECK_EQUAL(pool.poolLoad(), 0U);
+  BOOST_CHECK(!pool.shouldKeepStaleData());
 
   {
     const auto& servers = pool.getServers();
@@ -76,6 +77,7 @@ BOOST_AUTO_TEST_CASE(test_ServerPoolBasics)
     BOOST_CHECK(!pool.hasAtLeastOneServerAvailable());
     BOOST_CHECK_EQUAL(pool.countServers(true), 0U);
     BOOST_CHECK_EQUAL(pool.countServers(false), 1U);
+    BOOST_CHECK(pool.shouldKeepStaleData());
 
     BOOST_CHECK_EQUAL(pool.poolLoad(), 0U);
     {
@@ -88,11 +90,13 @@ BOOST_AUTO_TEST_CASE(test_ServerPoolBasics)
     BOOST_CHECK(pool.hasAtLeastOneServerAvailable());
     BOOST_CHECK_EQUAL(pool.countServers(true), 1U);
     BOOST_CHECK_EQUAL(pool.countServers(false), 1U);
+    BOOST_CHECK(!pool.shouldKeepStaleData());
 
     /* now remove it */
     pool.removeServer(ds);
     BOOST_CHECK_EQUAL(pool.countServers(true), 0U);
     BOOST_CHECK_EQUAL(pool.countServers(false), 0U);
+    BOOST_CHECK(!pool.shouldKeepStaleData());
     {
       const auto& servers = pool.getServers();
       BOOST_CHECK(servers.empty());