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:
tigercl 2019-08-23 14:41:52 +08:00 committed by GitHub
parent b924825fb9
commit ebc1bd77a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -639,14 +639,17 @@ handle_info({unsubscribe, TopicFilters}, Channel = #channel{client = Client}) ->
handle_info(sock_closed, Channel = #channel{connected = false}) ->
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),
case Interval of
?UINT_MAX ->
{ok, ensure_disconnected(Channel)};
{ok, ensure_disconnected(NChannel)};
Int when Int > 0 ->
{ok, ensure_timer(expire_timer, ensure_disconnected(Channel))};
_Other -> shutdown(closed, Channel)
{ok, ensure_timer(expire_timer, ensure_disconnected(NChannel))};
_Other -> shutdown(closed, NChannel)
end;
handle_info(Info, Channel) ->

View File

@ -143,7 +143,7 @@ t_handle_pingreq(_) ->
t_handle_disconnect(_) ->
with_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))
end).