From bbde5a64b260c957d3da9befa43eb30dd1ba6d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20J=C4=99drzejczak?= Date: Fri, 22 May 2026 11:08:49 +0200 Subject: [PATCH] compaction_manager: unregister compaction module on early shutdown The compaction module is registered with task_manager in the compaction_manager constructor, and unregistered in compaction_manager::really_do_stop(), which was gated behind `_state != state::none` in compaction_manager::do_stop(). Since enable() -- which transitions _state from none to running -- is called later during startup (from database::start() or the disk space monitor callback) than the compaction_manager constructor, an early shutdown could leave the compaction module registered after compaction_manager::do_stop() returned. task_manager::stop() then aborted with 'Tried to stop task manager while some modules were not unregistered'. Fix compaction_manager::do_stop() to call _task_manager_module->stop() even when `_state == state::none`, so that the compaction module is always properly unregistered. Fixes: SCYLLADB-2226 (cherry picked from commit 6cde390e2149f5bb9ea487ac40b0fb0425a4ad80) --- compaction/compaction_manager.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compaction/compaction_manager.cc b/compaction/compaction_manager.cc index e6ce55c1eb..d4884b049d 100644 --- a/compaction/compaction_manager.cc +++ b/compaction/compaction_manager.cc @@ -1301,9 +1301,16 @@ future<> compaction_manager::really_do_stop() noexcept { cmlog.info("Stopped"); } -// Should return immediately when _state == state::none. void compaction_manager::do_stop() noexcept { - if (_state == state::none || _stop_future) { + if (_stop_future) { + return; + } + + if (_state == state::none) { + // Possible when the node shuts down before enable() is called, + // e.g. due to an early startup failure. The task manager module + // was registered in the constructor and must be unregistered. + _stop_future = _task_manager_module->stop(); return; }