From 8f124b3aca6bdd3596c227c30664f906c508d725 Mon Sep 17 00:00:00 2001 From: i0gan <42000708+i0gan@users.noreply.github.com> Date: Sat, 9 Mar 2024 15:59:36 +0800 Subject: [PATCH] Bugfix: Clickhouse connect a closed network that will crash process. --- src/node/db_proxy/clickhouse/clickhouse_module.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/node/db_proxy/clickhouse/clickhouse_module.cc b/src/node/db_proxy/clickhouse/clickhouse_module.cc index 858e07d6..3d1489da 100644 --- a/src/node/db_proxy/clickhouse/clickhouse_module.cc +++ b/src/node/db_proxy/clickhouse/clickhouse_module.cc @@ -71,8 +71,14 @@ bool ClickhouseModule::Connect() { int port = m_element_->GetPropertyInt32(id, excel::DB::Port()); string password = m_element_->GetPropertyString(id, excel::DB::Auth()); /// Initialize client connection. - client_ = new Client(ClientOptions().SetHost(ip).SetPort(port).SetPassword(password)); - + try { + client_ = new Client(ClientOptions().SetHost(ip).SetPort(port).SetPassword(password)); + } + catch (const std::exception& e) { + std::cout << "Click connect error: " << e.what() << std::endl; + return false; + } + // Create a table. client_->Execute("CREATE TABLE IF NOT EXISTS default.numbers (id UInt64, name String) ENGINE = Memory");