]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: fix an other race in the metadata cache 9427/head
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 31 Aug 2020 11:27:56 +0000 (13:27 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 1 Sep 2020 13:52:16 +0000 (15:52 +0200)
pdns/dbdnsseckeeper.cc
pdns/dnsseckeeper.hh

index 60d9979afde162deca0506b4aa06e3615dd7d10b..47cee9baa536e3cedf67978898cedbbcaf1b2a34 100644 (file)
@@ -47,6 +47,7 @@ using namespace boost::assign;
 
 DNSSECKeeper::keycache_t DNSSECKeeper::s_keycache;
 DNSSECKeeper::metacache_t DNSSECKeeper::s_metacache;
+int64_t DNSSECKeeper::s_metaCacheCleanActions = 0;
 ReadWriteLock DNSSECKeeper::s_metacachelock;
 ReadWriteLock DNSSECKeeper::s_keycachelock;
 AtomicCounter DNSSECKeeper::s_ops;
@@ -132,6 +133,7 @@ bool DNSSECKeeper::clearMetaCache(const DNSName& name)
 {
   WriteLock l(&s_metacachelock);
   s_metacache.erase(name);
+  ++s_metaCacheCleanActions;
   return true;
 }
 
@@ -234,6 +236,9 @@ bool DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std
       meta = iter->d_value;
       fromCache = true;
     }
+    else {
+      d_metaCacheCleanAction = s_metaCacheCleanActions;
+    }
   }
 
   if (!fromCache) {
@@ -255,6 +260,9 @@ bool DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std
     nce.d_value = std::move(meta);
     {
       WriteLock l(&s_metacachelock);
+      if(d_metaCacheCleanAction != s_metaCacheCleanActions) {
+        return false;
+      }
       lruReplacingInsert<SequencedTag>(s_metacache, nce);
     }
   }
index 367e5b067dc982a9dc9dc3ab11b854528fdb02a8..f323b3adb1c684e5cc7566bb747af47a411421e4 100644 (file)
@@ -243,7 +243,7 @@ public:
 
   typedef std::map<std::string, std::vector<std::string> > METAValues;
 private:
-
+  int64_t d_metaCacheCleanAction{0};
 
   struct KeyCacheEntry
   {
@@ -295,6 +295,7 @@ private:
 
   static keycache_t s_keycache;
   static metacache_t s_metacache;
+  static int64_t s_metaCacheCleanActions;
   static ReadWriteLock s_metacachelock;
   static ReadWriteLock s_keycachelock;
   static AtomicCounter s_ops;