From 9a7c4c8401d858a3d370727b9b8387c89dbdeb4c Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 3 Mar 2023 09:14:55 +0100 Subject: [PATCH] rec: Backport 12347 to rec-4.x.8: Use correct logic for isEntryUsable() Backport of #12347 --- pdns/recursor_cache.cc | 4 ++-- pdns/recursor_cache.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index b4f08cab5f..2bf5d556e9 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -418,7 +418,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qt, F firstIndexIterator = map->d_map.project(i); // When serving stale, we consider expired records - if (i->isEntryUsable(now, serveStale)) { + if (!i->isEntryUsable(now, serveStale)) { moveCacheItemToFront(map->d_map, firstIndexIterator); continue; } @@ -459,7 +459,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qt, F firstIndexIterator = map->d_map.project(i); // When serving stale, we consider expired records - if (i->isEntryUsable(now, serveStale)) { + if (!i->isEntryUsable(now, serveStale)) { moveCacheItemToFront(map->d_map, firstIndexIterator); continue; } diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index 8d9e2e3a53..91102d99ae 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -104,7 +104,7 @@ private: bool isEntryUsable(time_t now, bool serveStale) const { // When serving stale, we consider expired records - return d_ttd <= now && !serveStale && d_servedStale == 0; + return d_ttd > now || serveStale || d_servedStale != 0; } bool shouldReplace(time_t now, bool auth, vState state, bool refresh); -- 2.47.2