From 9d6f96cfd8991a4999f82a506f1ccbd733365639 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Mon, 31 Aug 2020 13:27:56 +0200 Subject: [PATCH] auth: fix an other race in the metadata cache --- pdns/dbdnsseckeeper.cc | 8 ++++++++ pdns/dnsseckeeper.hh | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) 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; -- 2.47.2