]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent an infinite loop when a cache shard is below the limit
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 3 Mar 2021 09:33:12 +0000 (10:33 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 3 Mar 2021 09:33:12 +0000 (10:33 +0100)
pdns/dnsdist-cache.cc
pdns/test-dnsdistpacketcache_cc.cc

index 8bb38c2ff734c1e30c5a6c30815dcb96c5a523d3..a5a3865662fca8ac9c97f870329273dad9581f02 100644 (file)
@@ -305,6 +305,7 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now)
 
   do {
     uint32_t shardIndex = (d_expungeIndex++ % d_shardCount);
+    scannedMaps++;
 
     WriteLock w(&d_shards.at(shardIndex).d_lock);
     auto& map = d_shards.at(shardIndex).d_map;
@@ -325,8 +326,6 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now)
         ++it;
       }
     }
-
-    scannedMaps++;
   }
   while (scannedMaps < d_shardCount);
 
index c39a304d1133191118e49a5b7dd20ad798c8e4d0..3ac48628aa9f4d41b1815154868d9f44eb0497aa 100644 (file)
@@ -112,6 +112,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) {
     auto removed = PC.expungeByName(DNSName(" hello"), QType::ANY, true);
     BOOST_CHECK_EQUAL(PC.getSize(), 0U);
     BOOST_CHECK_EQUAL(removed, remaining);
+
+    /* nothing to remove */
+    BOOST_CHECK_EQUAL(PC.purgeExpired(0, now), 0U);
   }
   catch (const PDNSException& e) {
     cerr<<"Had error: "<<e.reason<<endl;
@@ -209,6 +212,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSharded) {
     removed = PC.purgeExpired(0, now + 7200 + 3600);
     BOOST_CHECK_EQUAL(removed, 1000U);
     BOOST_CHECK_EQUAL(PC.getSize(), 0U);
+
+    /* nothing to remove */
+    BOOST_CHECK_EQUAL(PC.purgeExpired(0, now), 0U);
   }
   catch (const PDNSException& e) {
     cerr<<"Had error: "<<e.reason<<endl;