Send the will message immediately when the network connection is closed by the client (#2834)
Send the will message immediately when the network connection is closed by the client
This commit is contained in:
parent
b924825fb9
commit
ebc1bd77a9
|
@ -639,14 +639,17 @@ handle_info({unsubscribe, TopicFilters}, Channel = #channel{client = Client}) ->
|
||||||
|
|
||||||
handle_info(sock_closed, Channel = #channel{connected = false}) ->
|
handle_info(sock_closed, Channel = #channel{connected = false}) ->
|
||||||
shutdown(closed, Channel);
|
shutdown(closed, Channel);
|
||||||
handle_info(sock_closed, Channel = #channel{session = Session}) ->
|
handle_info(sock_closed, Channel = #channel{protocol = Protocol,
|
||||||
|
session = Session}) ->
|
||||||
|
publish_will_msg(emqx_protocol:info(will_msg, Protocol)),
|
||||||
|
NChannel = Channel#channel{protocol = emqx_protocol:clear_will_msg(Protocol)},
|
||||||
Interval = emqx_session:info(expiry_interval, Session),
|
Interval = emqx_session:info(expiry_interval, Session),
|
||||||
case Interval of
|
case Interval of
|
||||||
?UINT_MAX ->
|
?UINT_MAX ->
|
||||||
{ok, ensure_disconnected(Channel)};
|
{ok, ensure_disconnected(NChannel)};
|
||||||
Int when Int > 0 ->
|
Int when Int > 0 ->
|
||||||
{ok, ensure_timer(expire_timer, ensure_disconnected(Channel))};
|
{ok, ensure_timer(expire_timer, ensure_disconnected(NChannel))};
|
||||||
_Other -> shutdown(closed, Channel)
|
_Other -> shutdown(closed, NChannel)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_info(Info, Channel) ->
|
handle_info(Info, Channel) ->
|
||||||
|
|
|
@ -143,7 +143,7 @@ t_handle_pingreq(_) ->
|
||||||
t_handle_disconnect(_) ->
|
t_handle_disconnect(_) ->
|
||||||
with_channel(
|
with_channel(
|
||||||
fun(Channel) ->
|
fun(Channel) ->
|
||||||
{stop, normal, Channel1} = handle_in(?DISCONNECT_PACKET(?RC_SUCCESS), Channel),
|
{stop, {shutdown, normal}, Channel1} = handle_in(?DISCONNECT_PACKET(?RC_SUCCESS), Channel),
|
||||||
?assertMatch(#{will_msg := undefined}, emqx_channel:info(protocol, Channel1))
|
?assertMatch(#{will_msg := undefined}, emqx_channel:info(protocol, Channel1))
|
||||||
end).
|
end).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue