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

fix(action/source api): improve returned error message on timeout

Thales Macedo Garitezi 1 год назад
Родитель
Сommit
f17aefe3d7

+ 12 - 1
apps/emqx_bridge/src/emqx_bridge_v2.erl

@@ -1151,7 +1151,18 @@ post_config_update([ConfRootKey, BridgeType, BridgeName], _Req, NewConf, undefin
 post_config_update([ConfRootKey, BridgeType, BridgeName], _Req, NewConf, OldConf, _AppEnvs) when
     ConfRootKey =:= ?ROOT_KEY_ACTIONS; ConfRootKey =:= ?ROOT_KEY_SOURCES
 ->
-    ok = uninstall_bridge_v2(ConfRootKey, BridgeType, BridgeName, OldConf),
+    case uninstall_bridge_v2(ConfRootKey, BridgeType, BridgeName, OldConf) of
+        ok ->
+            ok;
+        {error, timeout} ->
+            throw(<<
+                "Timed out trying to remove action or source.  Please try again and,"
+                " if the error persists, try disabling the connector before retrying."
+            >>);
+        {error, not_found} ->
+            %% Should not happen, unless config is inconsistent.
+            throw(<<"Referenced connector not found">>)
+    end,
     ok = install_bridge_v2(ConfRootKey, BridgeType, BridgeName, NewConf),
     Bridges = emqx_utils_maps:deep_put(
         [BridgeType, BridgeName], emqx:get_config([ConfRootKey]), NewConf

+ 2 - 0
apps/emqx_bridge/src/emqx_bridge_v2_api.erl

@@ -879,6 +879,8 @@ handle_disable_enable(ConfRootKey, Id, Enable) ->
                 ?SERVICE_UNAVAILABLE(<<"request timeout">>);
             {error, timeout} ->
                 ?SERVICE_UNAVAILABLE(<<"request timeout">>);
+            {error, Reason} when is_binary(Reason) ->
+                ?BAD_REQUEST(Reason);
             {error, Reason} ->
                 ?INTERNAL_ERROR(Reason)
         end

+ 3 - 0
changes/ce/fix-13181.en.md

@@ -0,0 +1,3 @@
+Now, when attempting to stop a connector, if such operation times out, we forcefully shut down the connector process.
+
+Error messages when attempting to disable an action/source when its underlying connector is stuck were also improved.