From: Kees Monshouwer Date: Mon, 31 Aug 2020 11:27:56 +0000 (+0200) Subject: auth: fix an other race in the metadata cache X-Git-Tag: auth-4.4.0-alpha1~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9427%2Fhead;p=thirdparty%2Fpdns.git auth: fix an other race in the metadata cache --- diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 60d9979afd..47cee9baa5 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -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(s_metacache, nce); } } diff --git a/pdns/dnsseckeeper.hh b/pdns/dnsseckeeper.hh index 367e5b067d..f323b3adb1 100644 --- a/pdns/dnsseckeeper.hh +++ b/pdns/dnsseckeeper.hh @@ -243,7 +243,7 @@ public: typedef std::map > 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;