fix: clean session when destroy mqtt bridge

This commit is contained in:
DDDHuang 2022-05-13 10:28:29 +08:00
parent bcac65310b
commit 9744040795
1 changed files with 14 additions and 0 deletions

View File

@ -276,6 +276,20 @@ code_change(_Vsn, State, Data, _Extra) ->
terminate(_Reason, _StateName, #{replayq := Q} = State) -> terminate(_Reason, _StateName, #{replayq := Q} = State) ->
_ = disconnect(State), _ = disconnect(State),
_ = replayq:close(Q), _ = replayq:close(Q),
maybe_destroy_session(State).
maybe_destroy_session(#{connect_opts := ConnectOpts = #{clean_start := false}} = State) ->
try
%% Destroy session if clean_start is not set.
%% Ignore any crashes, just refresh the clean_start = true.
_ = do_connect(State#{connect_opts => ConnectOpts#{clean_start => true}}),
_ = disconnect(State),
ok
catch
_:_ ->
ok
end;
maybe_destroy_session(_State) ->
ok. ok.
%% ensure_started will be deprecated in the future %% ensure_started will be deprecated in the future