From ca24bebcf248eeb9d42ac6f479ce97c8dc0efa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Wed, 5 Jan 2022 16:08:54 +0200 Subject: [PATCH] sstables/partition_index_cache: destroy entry ptr on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error-handling code removes the cache entry but this leads to an assertion because the entry is still referenced by the entry pointer instance which is returned on the normal path. To avoid this clear the pointer on the error path and make sure there are no additional references kept to it. Fixes #9887 Signed-off-by: Botond Dénes Message-Id: <20220105140859.586234-2-bdenes@scylladb.com> (cherry picked from commit 92727ac36c311e09adf8bcf0946637e35c7d0994) --- sstables/partition_index_cache.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sstables/partition_index_cache.hh b/sstables/partition_index_cache.hh index 79f1bd0e12..4c68a491b7 100644 --- a/sstables/partition_index_cache.hh +++ b/sstables/partition_index_cache.hh @@ -233,7 +233,7 @@ public: // No exceptions before then_wrapped() is installed so that ptr will be eventually populated. - return futurize_invoke(loader, key).then_wrapped([this, key, ptr] (auto&& f) mutable { + return futurize_invoke(loader, key).then_wrapped([this, key, ptr = std::move(ptr)] (auto&& f) mutable { entry& e = ptr.get_entry(); try { partition_index_page&& page = f.get0(); @@ -241,15 +241,15 @@ public: e.set_page(std::move(page)); _shard_stats.used_bytes += e.size_in_allocator(); ++_shard_stats.populations; + return ptr; } catch (...) { e.promise()->set_exception(std::current_exception()); + ptr = {}; with_allocator(_region.allocator(), [&] { _cache.erase(key); }); throw; } - }).then([ptr] { - return ptr; }); }