From 6cf8f84ffbb4a6a4f943d36dc0160a7de09e3deb Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 22 Feb 2021 17:26:14 +0100 Subject: [PATCH] rec: Don't delete aggressive cache entries while they are locked --- pdns/recursordist/aggressive_nsec.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index 053dd2c3a9..ca02233248 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -101,10 +101,16 @@ void AggressiveNSECCache::removeZoneInfo(const DNSName& zone, bool subzones) return; } - std::lock_guard lock((*got)->d_lock); - auto removed = (*got)->d_entries.size(); - d_zones.remove(zone, false); - d_entriesCount -= removed; + /* let's increase the ref count of the shared pointer + so we get the lock, remove the zone from the tree, + then release the lock before the entry is deleted */ + auto entry = *got; + { + std::lock_guard lock(entry->d_lock); + auto removed = entry->d_entries.size(); + d_zones.remove(zone, false); + d_entriesCount -= removed; + } } } -- 2.47.2