From 0cec52d5e4da6f790916f09aa468e75f6408a674 Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Tue, 4 Apr 2023 12:01:41 +0200 Subject: [PATCH] fix: check Clickhouse connection after creation When pressing reconnect on a badly configured Clickhouse bridge in the dashboard, no error message was shown. This commit fixes this issue by testing the connection after creation and returning an error tuple if the connection is not working. Fixes: https://emqx.atlassian.net/browse/EMQX-9374 --- changes/ee/fix-10324.en.md | 1 + changes/ee/fix-10324.zh.md | 1 + .../src/emqx_ee_connector_clickhouse.erl | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changes/ee/fix-10324.en.md create mode 100644 changes/ee/fix-10324.zh.md diff --git a/changes/ee/fix-10324.en.md b/changes/ee/fix-10324.en.md new file mode 100644 index 000000000..2d4c323da --- /dev/null +++ b/changes/ee/fix-10324.en.md @@ -0,0 +1 @@ +Previously, when attempting to reconnect to a misconfigured Clickhouse bridge through the dashboard, users would not receive an error message. This issue is now resolved, and error messages will now be displayed diff --git a/changes/ee/fix-10324.zh.md b/changes/ee/fix-10324.zh.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/changes/ee/fix-10324.zh.md @@ -0,0 +1 @@ + diff --git a/lib-ee/emqx_ee_connector/src/emqx_ee_connector_clickhouse.erl b/lib-ee/emqx_ee_connector/src/emqx_ee_connector_clickhouse.erl index 8f2fdc042..5d68687dc 100644 --- a/lib-ee/emqx_ee_connector/src/emqx_ee_connector_clickhouse.erl +++ b/lib-ee/emqx_ee_connector/src/emqx_ee_connector_clickhouse.erl @@ -270,8 +270,15 @@ connect(Options) -> {pool_size, PoolSize} ], case clickhouse:start_link(FixedOptions) of - {ok, _Conn} = Ok -> - Ok; + {ok, Connection} -> + %% Check if we can connect and send a query + case clickhouse:detailed_status(Connection) of + ok -> + {ok, Connection}; + Error -> + ok = clickhouse:stop(Connection), + Error + end; {error, Reason} -> {error, Reason} end.