Explorar o código

fix: stopping mqtt-bridge prints an error log if subscribe failed

Shawn hai 1 ano
pai
achega
a813eb44db

+ 1 - 1
apps/emqx_bridge_mqtt/src/emqx_bridge_mqtt.app.src

@@ -1,7 +1,7 @@
 %% -*- mode: erlang -*-
 {application, emqx_bridge_mqtt, [
     {description, "EMQX MQTT Broker Bridge"},
-    {vsn, "0.2.5"},
+    {vsn, "0.2.6"},
     {registered, []},
     {applications, [
         kernel,

+ 18 - 16
apps/emqx_bridge_mqtt/src/emqx_bridge_mqtt_connector.erl

@@ -175,22 +175,24 @@ on_remove_channel(
     } = OldState,
     ChannelId
 ) ->
-    ChannelState = maps:get(ChannelId, InstalledChannels),
-    case ChannelState of
-        #{
-            config_root := sources
-        } ->
-            emqx_bridge_mqtt_ingress:unsubscribe_channel(
-                PoolName, ChannelState, ChannelId, TopicToHandlerIndex
-            ),
-            ok;
-        _ ->
-            ok
-    end,
-    NewInstalledChannels = maps:remove(ChannelId, InstalledChannels),
-    %% Update state
-    NewState = OldState#{installed_channels => NewInstalledChannels},
-    {ok, NewState}.
+    case maps:find(ChannelId, InstalledChannels) of
+        error ->
+            %% maybe the channel failed to be added, just ignore it
+            {ok, OldState};
+        {ok, ChannelState} ->
+            case ChannelState of
+                #{config_root := sources} ->
+                    ok = emqx_bridge_mqtt_ingress:unsubscribe_channel(
+                        PoolName, ChannelState, ChannelId, TopicToHandlerIndex
+                    );
+                _ ->
+                    ok
+            end,
+            NewInstalledChannels = maps:remove(ChannelId, InstalledChannels),
+            %% Update state
+            NewState = OldState#{installed_channels => NewInstalledChannels},
+            {ok, NewState}
+    end.
 
 on_get_channel_status(
     _ResId,

+ 1 - 0
changes/ce/fix-14265.en.md

@@ -0,0 +1 @@
+If the MQTT Source action fails to subscribe successfully, a `badkey` error will occur when stopping the connector.