Merge pull request #7940 from DDDHuang/mqtt_bridge_cs

fix: clean session when destroy mqtt bridge
This commit is contained in:
DDDHuang 2022-05-13 16:04:09 +08:00 committed by GitHub
commit 448f9b5c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) ->
_ = disconnect(State),
_ = 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.
%% ensure_started will be deprecated in the future