From f17aefe3d7746da91c917907536a7f6ae2b52317 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 4 Jun 2024 11:59:00 -0300 Subject: [PATCH] fix(action/source api): improve returned error message on timeout --- apps/emqx_bridge/src/emqx_bridge_v2.erl | 13 ++++++++++++- apps/emqx_bridge/src/emqx_bridge_v2_api.erl | 2 ++ changes/ce/fix-13181.en.md | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changes/ce/fix-13181.en.md diff --git a/apps/emqx_bridge/src/emqx_bridge_v2.erl b/apps/emqx_bridge/src/emqx_bridge_v2.erl index e6feac7bd..79e8fc8f8 100644 --- a/apps/emqx_bridge/src/emqx_bridge_v2.erl +++ b/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 diff --git a/apps/emqx_bridge/src/emqx_bridge_v2_api.erl b/apps/emqx_bridge/src/emqx_bridge_v2_api.erl index 8ba2ef487..99caba625 100644 --- a/apps/emqx_bridge/src/emqx_bridge_v2_api.erl +++ b/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 diff --git a/changes/ce/fix-13181.en.md b/changes/ce/fix-13181.en.md new file mode 100644 index 000000000..984a9af76 --- /dev/null +++ b/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.