From 57798a19c0ad4a9c22e2c13d28dcf1f4256995e2 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:37:33 +0200 Subject: [PATCH] add SCOPE_EXIT --- programs/server/Server.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/programs/server/Server.cpp b/programs/server/Server.cpp index 2feba9dfc46..5f3ab278060 100644 --- a/programs/server/Server.cpp +++ b/programs/server/Server.cpp @@ -1101,10 +1101,6 @@ try PlacementInfo::PlacementInfo::instance().initialize(config()); - auto cancellation_task_holder = global_context->getSchedulePool().createTask("CancellationChecker", []{ CancellationChecker::getInstance().workerFunction(); }); - auto cancellation_task = std::make_unique(std::move(cancellation_task_holder)); - (*cancellation_task)->activateAndSchedule(); - zkutil::validateZooKeeperConfig(config()); bool has_zookeeper = zkutil::hasZooKeeperConfig(config()); @@ -1249,6 +1245,14 @@ try setOOMScore(oom_score, log); #endif + auto cancellation_task_holder = global_context->getSchedulePool().createTask("CancellationChecker", []{ CancellationChecker::getInstance().workerFunction(); }); + auto cancellation_task = std::make_unique(std::move(cancellation_task_holder)); + (*cancellation_task)->activateAndSchedule(); + + SCOPE_EXIT({ + CancellationChecker::getInstance().terminateThread(); + }); + global_context->setRemoteHostFilter(config()); global_context->setHTTPHeaderFilter(config()); @@ -2318,8 +2322,6 @@ try if (current_connections) current_connections = waitServersToFinish(servers, servers_lock, server_settings.shutdown_wait_unfinished); - CancellationChecker::getInstance().terminateThread(); - if (current_connections) LOG_WARNING(log, "Closed connections. But {} remain." " Tip: To increase wait time add to config: 60", current_connections);