From 4a0c572440c7df2f56a6f5fb5aec9e366d522edb Mon Sep 17 00:00:00 2001 From: leveldb Team Date: Fri, 6 Mar 2026 21:29:47 +0000 Subject: [PATCH] Fix TEST_CompactMemTable deadlock This CL ensures that CompactRange doesn't get stuck on waiting on background_work_finished_signal_ during shutdown. While background_work_finished_signal_ may be in fact signaled, CompactMemTable() will never run, not giving opportunity for workers blocked in TEST_CompactMemTable to exit the loop. We suspect this contributes to b/370844779; while the hang was mitigated by limiting concurrency to 1 worker (which avoids filling the thread pool with blocked workers), this issue can still happen and will block 1 worker during shutdown. PiperOrigin-RevId: 879794057 --- db/db_impl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index f96d245..ce4ef82 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -646,7 +646,8 @@ Status DBImpl::TEST_CompactMemTable() { if (s.ok()) { // Wait until the compaction completes MutexLock l(&mutex_); - while (imm_ != nullptr && bg_error_.ok()) { + while (imm_ != nullptr && bg_error_.ok() && + !shutting_down_.load(std::memory_order_acquire)) { background_work_finished_signal_.Wait(); } if (imm_ != nullptr) {