From 9d026ef7333160d2aaf3be61e629dcc868586ec0 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Mar 2019 22:30:01 +0300 Subject: [PATCH 1/2] Avoid deadlock on exit if exception was thrown in loadMetadata due to cyclic references in ContextShared that holds BackgroundProcessingPool --- dbms/programs/server/Server.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dbms/programs/server/Server.cpp b/dbms/programs/server/Server.cpp index 213a6e126df..2b10c9e3c98 100644 --- a/dbms/programs/server/Server.cpp +++ b/dbms/programs/server/Server.cpp @@ -260,6 +260,15 @@ int Server::main(const std::vector & /*args*/) StatusFile status{path + "status"}; SCOPE_EXIT({ + /** Ask to cancel background jobs all table engines, + * and also query_log. + * It is important to do early, not in destructor of Context, because + * table engines could use Context on destroy. + */ + LOG_INFO(log, "Shutting down storages."); + global_context->shutdown(); + LOG_DEBUG(log, "Shutted down storages."); + /** Explicitly destroy Context. It is more convenient than in destructor of Server, because logger is still available. * At this moment, no one could own shared part of Context. */ @@ -498,17 +507,6 @@ int Server::main(const std::vector & /*args*/) global_context->setCurrentDatabase(default_database); - SCOPE_EXIT({ - /** Ask to cancel background jobs all table engines, - * and also query_log. - * It is important to do early, not in destructor of Context, because - * table engines could use Context on destroy. - */ - LOG_INFO(log, "Shutting down storages."); - global_context->shutdown(); - LOG_DEBUG(log, "Shutted down storages."); - }); - if (has_zookeeper && config().has("distributed_ddl")) { /// DDL worker should be started after all tables were loaded From 1ca16d788236c058ea592ef8bb28714873952db1 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Mar 2019 22:30:59 +0300 Subject: [PATCH 2/2] Fix "bad_alloc" handler clobbering by LLVM library --- dbms/programs/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbms/programs/main.cpp b/dbms/programs/main.cpp index 34b04a0d7fe..15f1673985b 100644 --- a/dbms/programs/main.cpp +++ b/dbms/programs/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -139,6 +140,10 @@ bool isClickhouseApp(const std::string & app_suffix, std::vector & argv) int main(int argc_, char ** argv_) { + /// Reset new handler to default (that throws std::bad_alloc) + /// It is needed because LLVM library clobbers it. + std::set_new_handler(nullptr); + #if USE_EMBEDDED_COMPILER if (argc_ >= 2 && 0 == strcmp(argv_[1], "-cc1")) return mainEntryClickHouseClang(argc_, argv_);