From 136ccff3536c4fa083ed11af838dcc93fbfa4e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chojnowski?= Date: Fri, 9 Aug 2024 14:05:44 +0200 Subject: [PATCH] cql_test_env: ensure shutdown() before stop() for system_keyspace If system_keyspace::stop() is called before system_keyspace::shutdown(), it will never finish, because the uncleared shared pointers will keep it alive indefinitely. Currently this can happen if an exception is thrown before the construction of the shutdown() defer. This patch moves the shutdown() call to immediately before stop(). I see no reason why it should be elsewhere. Fixes scylladb/scylla-enterprise#4380 (cherry picked from commit eeaf4c344337ba2c16357cd52ffa1a4cdea635b8) Closes scylladb/scylladb#20146 --- test/lib/cql_test_env.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index 5e4bb89d20..982f373566 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -615,7 +615,10 @@ private: _sl_controller.invoke_on_all(&qos::service_level_controller::start).get(); _sys_ks.start(std::ref(_qp), std::ref(_db)).get(); - auto stop_sys_kd = defer([this] { _sys_ks.stop().get(); }); + auto stop_sys_kd = defer([this] { + _sys_ks.invoke_on_all(&db::system_keyspace::shutdown).get(); + _sys_ks.stop().get(); + }); replica::distributed_loader::init_system_keyspace(_sys_ks, _erm_factory, _db).get(); _db.local().maybe_init_schema_commitlog(); @@ -785,9 +788,6 @@ private: } group0_client.init().get(); - auto stop_system_keyspace = defer([this] { - _sys_ks.invoke_on_all(&db::system_keyspace::shutdown).get(); - }); auto shutdown_db = defer([this] { _db.invoke_on_all(&replica::database::shutdown).get();