Просмотр исходного кода

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
Kjell Winblad 2 лет назад
Родитель
Сommit
0cec52d5e4

+ 1 - 0
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

+ 1 - 0
changes/ee/fix-10324.zh.md

@@ -0,0 +1 @@
+

+ 9 - 2
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.