fix: check conn state before sending will message
This commit is contained in:
parent
6269c10502
commit
87ab2e3a2d
|
@ -1434,15 +1434,24 @@ terminate({shutdown, kicked}, Channel) ->
|
||||||
run_terminate_hook(kicked, Channel);
|
run_terminate_hook(kicked, Channel);
|
||||||
terminate({shutdown, Reason}, Channel) when
|
terminate({shutdown, Reason}, Channel) when
|
||||||
Reason =:= discarded;
|
Reason =:= discarded;
|
||||||
Reason =:= takenover;
|
Reason =:= takenover
|
||||||
Reason =:= not_authorized
|
|
||||||
->
|
->
|
||||||
run_terminate_hook(Reason, Channel);
|
run_terminate_hook(Reason, Channel);
|
||||||
terminate(Reason, Channel = #channel{will_msg = WillMsg}) ->
|
terminate(Reason, Channel = #channel{will_msg = WillMsg}) ->
|
||||||
(WillMsg =/= undefined) andalso publish_will_msg(WillMsg),
|
should_publish_will_message(Reason, Channel) andalso publish_will_msg(WillMsg),
|
||||||
(Reason =:= expired) andalso persist_if_session(Channel),
|
(Reason =:= expired) andalso persist_if_session(Channel),
|
||||||
run_terminate_hook(Reason, Channel).
|
run_terminate_hook(Reason, Channel).
|
||||||
|
|
||||||
|
should_publish_will_message(TerminateReason, Channel) ->
|
||||||
|
not lists:member(TerminateReason, [
|
||||||
|
{shutdown, kicked},
|
||||||
|
{shutdown, discarded},
|
||||||
|
{shutdown, takenover},
|
||||||
|
{shutdown, not_authorized}
|
||||||
|
]) andalso
|
||||||
|
not lists:member(info(conn_state, Channel), [idle, connecting]) andalso
|
||||||
|
info(will_msg, Channel) =/= undefined.
|
||||||
|
|
||||||
persist_if_session(#channel{session = Session} = Channel) ->
|
persist_if_session(#channel{session = Session} = Channel) ->
|
||||||
case emqx_session:is_session(Session) of
|
case emqx_session:is_session(Session) of
|
||||||
true ->
|
true ->
|
||||||
|
|
Loading…
Reference in New Issue