fix(mqtt_bridge): handle send_to_remote in idle state

This commit is contained in:
Shawn 2022-09-14 15:19:30 +08:00
parent f41adb0997
commit 1c03c236f5
2 changed files with 6 additions and 2 deletions

View File

@ -276,6 +276,8 @@ idle({call, From}, ensure_started, State) ->
{error, Reason, _State} -> {error, Reason, _State} ->
{keep_state_and_data, [{reply, From, {error, Reason}}]} {keep_state_and_data, [{reply, From, {error, Reason}}]}
end; end;
idle({call, From}, send_to_remote, _State) ->
{keep_state_and_data, [{reply, From, {error, {recoverable_error, not_connected}}}]};
%% @doc Standing by for manual start. %% @doc Standing by for manual start.
idle(info, idle, #{start_type := manual}) -> idle(info, idle, #{start_type := manual}) ->
keep_state_and_data; keep_state_and_data;
@ -339,10 +341,12 @@ common(_StateName, {call, From}, get_forwards, #{connect_opts := #{forwards := F
{keep_state_and_data, [{reply, From, Forwards}]}; {keep_state_and_data, [{reply, From, Forwards}]};
common(_StateName, {call, From}, get_subscriptions, #{connection := Connection}) -> common(_StateName, {call, From}, get_subscriptions, #{connection := Connection}) ->
{keep_state_and_data, [{reply, From, maps:get(subscriptions, Connection, #{})}]}; {keep_state_and_data, [{reply, From, maps:get(subscriptions, Connection, #{})}]};
common(_StateName, {call, From}, Req, _State) ->
{keep_state_and_data, [{reply, From, {unsuppored_request, Req}}]};
common(_StateName, info, {'EXIT', _, _}, State) -> common(_StateName, info, {'EXIT', _, _}, State) ->
{keep_state, State}; {keep_state, State};
common(StateName, Type, Content, #{name := Name} = State) -> common(StateName, Type, Content, #{name := Name} = State) ->
?SLOG(notice, #{ ?SLOG(error, #{
msg => "bridge_discarded_event", msg => "bridge_discarded_event",
name => Name, name => Name,
type => Type, type => Type,

View File

@ -467,11 +467,11 @@ retry_actions(Data) ->
handle_remove_event(From, ClearMetrics, Data) -> handle_remove_event(From, ClearMetrics, Data) ->
stop_resource(Data), stop_resource(Data),
ok = emqx_resource_worker_sup:stop_workers(Data#data.id, Data#data.opts),
case ClearMetrics of case ClearMetrics of
true -> ok = emqx_metrics_worker:clear_metrics(?RES_METRICS, Data#data.id); true -> ok = emqx_metrics_worker:clear_metrics(?RES_METRICS, Data#data.id);
false -> ok false -> ok
end, end,
ok = emqx_resource_worker_sup:stop_workers(Data#data.id, Data#data.opts),
{stop_and_reply, normal, [{reply, From, ok}]}. {stop_and_reply, normal, [{reply, From, ok}]}.
start_resource(Data, From) -> start_resource(Data, From) ->