From b320b20c7b7328a18a77edcf8db97619069d4348 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 6 May 2024 16:17:02 +0800 Subject: [PATCH] fix(mqtt): disconnected event should not be sent twice --- apps/emqx/src/emqx_channel.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/emqx/src/emqx_channel.erl b/apps/emqx/src/emqx_channel.erl index b3b384541..eb54f6ba1 100644 --- a/apps/emqx/src/emqx_channel.erl +++ b/apps/emqx/src/emqx_channel.erl @@ -2636,10 +2636,15 @@ disconnect_and_shutdown( -> NChannel = ensure_disconnected(Reason, Channel), shutdown(Reason, Reply, ?DISCONNECT_PACKET(reason_code(Reason)), NChannel); -%% mqtt v3/v4 sessions, mqtt v5 other conn_state sessions -disconnect_and_shutdown(Reason, Reply, Channel) -> +%% mqtt v3/v4 connected sessions +disconnect_and_shutdown(Reason, Reply, Channel = #channel{conn_state = ConnState}) when + ConnState =:= connected orelse ConnState =:= reauthenticating +-> 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]}). sp(true) -> 1;