From c42943850fdac72fa704ee94186f5be235bef97e Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 9 May 2020 16:02:37 +0300 Subject: [PATCH] Avoid std::terminate in case of exception from SystemLogs::SystemLogs Since, at least, this will hide the real exception --- src/Interpreters/SystemLog.cpp | 18 ++++++++++++++---- src/Interpreters/SystemLog.h | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Interpreters/SystemLog.cpp b/src/Interpreters/SystemLog.cpp index cfb31ab2a41..e2e29b3c899 100644 --- a/src/Interpreters/SystemLog.cpp +++ b/src/Interpreters/SystemLog.cpp @@ -98,11 +98,21 @@ SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfi logs.emplace_back(metric_log.get()); bool lazy_load = config.getBool("system_tables_lazy_load", true); - for (auto & log : logs) + + try { - if (!lazy_load) - log->prepareTable(); - log->startup(); + for (auto & log : logs) + { + if (!lazy_load) + log->prepareTable(); + log->startup(); + } + } + catch (...) + { + /// join threads + shutdown(); + throw; } } diff --git a/src/Interpreters/SystemLog.h b/src/Interpreters/SystemLog.h index 066956ed53a..f5a024c7768 100644 --- a/src/Interpreters/SystemLog.h +++ b/src/Interpreters/SystemLog.h @@ -208,6 +208,7 @@ SystemLog::SystemLog(Context & context_, template void SystemLog::startup() { + std::unique_lock lock(mutex); saving_thread = ThreadFromGlobalPool([this] { savingThreadFunction(); }); } @@ -288,6 +289,11 @@ void SystemLog::stopFlushThread() { std::unique_lock lock(mutex); + if (!saving_thread.joinable()) + { + return; + } + if (is_shutdown) { return;