فهرست منبع

Merge pull request #13973 from id/20241010-handle-odbc-disconnect-in-mssql

fix: call odbc:disconnect/1 when sqlserver pool worker is terminated
Ivan Dyachkov 1 سال پیش
والد
کامیت
2f219f288b
2فایلهای تغییر یافته به همراه12 افزوده شده و 3 حذف شده
  1. 11 3
      apps/emqx_bridge_sqlserver/src/emqx_bridge_sqlserver_connector.erl
  2. 1 0
      changes/ee/fix-13973.en.md

+ 11 - 3
apps/emqx_bridge_sqlserver/src/emqx_bridge_sqlserver_connector.erl

@@ -44,8 +44,11 @@
     on_format_query_result/1
 ]).
 
-%% callbacks for ecpool
--export([connect/1]).
+%% `ecpool_worker' API
+-export([
+    connect/1,
+    disconnect/1
+]).
 
 %% Internal exports used to execute code with ecpool worker
 -export([do_get_status/1, worker_do_insert/3]).
@@ -213,7 +216,8 @@ on_start(
         {password, maps:get(password, Config, emqx_secret:wrap(""))},
         {driver, Driver},
         {database, Database},
-        {pool_size, PoolSize}
+        {pool_size, PoolSize},
+        {on_disconnect, {?MODULE, disconnect, []}}
     ],
 
     State = #{
@@ -350,6 +354,10 @@ connect(Options) ->
     Opts = proplists:get_value(options, Options, []),
     odbc:connect(ConnectStr, Opts).
 
+-spec disconnect(connection_reference()) -> ok | {error, term()}.
+disconnect(ConnectionPid) ->
+    odbc:disconnect(ConnectionPid).
+
 -spec do_get_status(connection_reference()) -> Result :: boolean().
 do_get_status(Conn) ->
     case execute(Conn, <<"SELECT 1">>) of

+ 1 - 0
changes/ee/fix-13973.en.md

@@ -0,0 +1 @@
+Fix an issue with MS SQL Server integration when EMQX would print a few errors and warnings in the log each time connection to the server is stopped.