Skip to content

Commit

Permalink
add signal handlers in client and local
Browse files Browse the repository at this point in the history
  • Loading branch information
tavplubix committed Mar 8, 2024
1 parent f73a8f2 commit 72ac59f
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 605 deletions.
17 changes: 16 additions & 1 deletion src/Client/ClientBase.cpp
Expand Up @@ -22,6 +22,7 @@
#include <Common/StringUtils/StringUtils.h>
#include <Common/filesystemHelpers.h>
#include <Common/NetException.h>
#include <Common/SignalHandlers.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
#include <Formats/FormatFactory.h>
Expand Down Expand Up @@ -300,7 +301,13 @@ class LocalFormatError : public DB::Exception
};


ClientBase::~ClientBase() = default;
ClientBase::~ClientBase()
{
writeSignalIDtoSignalPipe(SignalListener::StopThread);
signal_listener_thread.join();
HandledSignals::instance().reset();
}

ClientBase::ClientBase() = default;


Expand Down Expand Up @@ -3007,6 +3014,14 @@ void ClientBase::init(int argc, char ** argv)
}

has_log_comment = config().has("log_comment");

/// Print stacktrace in case of crash
HandledSignals::instance().setupCommonDeadlySignalHandlers();

fatal_channel_ptr = new Poco::ConsoleChannel;
fatal_log = createLogger("ClientBase", fatal_channel_ptr.get(), Poco::Message::PRIO_TRACE);
signal_listener = std::make_unique<SignalListener>(nullptr, fatal_log);
signal_listener_thread.start(*signal_listener);
}

}
6 changes: 6 additions & 0 deletions src/Client/ClientBase.h
Expand Up @@ -10,6 +10,7 @@
#include <Common/DNSResolver.h>
#include <Core/ExternalTable.h>
#include <Poco/Util/Application.h>
#include <Poco/ConsoleChannel.h>
#include <Interpreters/Context.h>
#include <Client/Suggest.h>
#include <Client/QueryFuzzer.h>
Expand Down Expand Up @@ -192,6 +193,11 @@ class ClientBase : public Poco::Util::Application, public IHints<2>
SharedContextHolder shared_context;
ContextMutablePtr global_context;

LoggerPtr fatal_log;
Poco::AutoPtr<Poco::Channel> fatal_channel_ptr;
Poco::Thread signal_listener_thread;
std::unique_ptr<Poco::Runnable> signal_listener;

bool is_interactive = false; /// Use either interactive line editing interface or batch mode.
bool is_multiquery = false;
bool delayed_interactive = false;
Expand Down

0 comments on commit 72ac59f

Please sign in to comment.