fix(mqtt): disconnected event should not be sent twice

This commit is contained in:
JianBo He 2024-05-06 16:17:02 +08:00
parent 004dc80fb2
commit b320b20c7b
1 changed files with 8 additions and 3 deletions

View File

@ -2636,10 +2636,15 @@ disconnect_and_shutdown(
-> ->
NChannel = ensure_disconnected(Reason, Channel), NChannel = ensure_disconnected(Reason, Channel),
shutdown(Reason, Reply, ?DISCONNECT_PACKET(reason_code(Reason)), NChannel); shutdown(Reason, Reply, ?DISCONNECT_PACKET(reason_code(Reason)), NChannel);
%% mqtt v3/v4 sessions, mqtt v5 other conn_state sessions %% mqtt v3/v4 connected sessions
disconnect_and_shutdown(Reason, Reply, Channel) -> disconnect_and_shutdown(Reason, Reply, Channel = #channel{conn_state = ConnState}) when
ConnState =:= connected orelse ConnState =:= reauthenticating
->
NChannel = ensure_disconnected(Reason, Channel), NChannel = ensure_disconnected(Reason, Channel),
shutdown(Reason, Reply, NChannel). shutdown(Reason, Reply, NChannel);
%% other conn_state sessions
disconnect_and_shutdown(Reason, Reply, Channel) ->
shutdown(Reason, Reply, Channel).
-compile({inline, [sp/1, flag/1]}). -compile({inline, [sp/1, flag/1]}).
sp(true) -> 1; sp(true) -> 1;