From 597558fee885262ffd2ac5faaf2c663d285402ff Mon Sep 17 00:00:00 2001 From: zhouzb Date: Mon, 30 Dec 2019 12:00:31 +0800 Subject: [PATCH] Fix unexpected timeout --- src/emqx_channel.erl | 20 ++++++++------------ src/emqx_connection.erl | 8 ++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/emqx_channel.erl b/src/emqx_channel.erl index 9b35b42b1..2dec4d98a 100644 --- a/src/emqx_channel.erl +++ b/src/emqx_channel.erl @@ -786,9 +786,8 @@ handle_info(Info, Channel) -> -> {ok, channel()} | {ok, replies(), channel()} | {shutdown, Reason :: term(), channel()}). -handle_timeout(TRef, {keepalive, StatVal}, - Channel = #channel{keepalive = Keepalive, - timers = #{alive_timer := TRef}}) -> +handle_timeout(_TRef, {keepalive, StatVal}, + Channel = #channel{keepalive = Keepalive}) -> case emqx_keepalive:check(StatVal, Keepalive) of {ok, NKeepalive} -> NChannel = Channel#channel{keepalive = NKeepalive}, @@ -797,9 +796,8 @@ handle_timeout(TRef, {keepalive, StatVal}, handle_out(disconnect, ?RC_KEEP_ALIVE_TIMEOUT, Channel) end; -handle_timeout(TRef, retry_delivery, - Channel = #channel{session = Session, - timers = #{retry_timer := TRef}}) -> +handle_timeout(_TRef, retry_delivery, + Channel = #channel{session = Session}) -> case emqx_session:retry(Session) of {ok, NSession} -> {ok, clean_timer(retry_timer, Channel#channel{session = NSession})}; @@ -811,9 +809,8 @@ handle_timeout(TRef, retry_delivery, handle_out(publish, Publishes, reset_timer(retry_timer, Timeout, NChannel)) end; -handle_timeout(TRef, expire_awaiting_rel, - Channel = #channel{session = Session, - timers = #{await_timer := TRef}}) -> +handle_timeout(_TRef, expire_awaiting_rel, + Channel = #channel{session = Session}) -> case emqx_session:expire(awaiting_rel, Session) of {ok, Session} -> {ok, clean_timer(await_timer, Channel#channel{session = Session})}; @@ -821,11 +818,10 @@ handle_timeout(TRef, expire_awaiting_rel, {ok, reset_timer(await_timer, Timeout, Channel#channel{session = Session})} end; -handle_timeout(TRef, expire_session, Channel = #channel{timers = #{expire_timer := TRef}}) -> +handle_timeout(_TRef, expire_session, Channel) -> shutdown(expired, Channel); -handle_timeout(TRef, will_message, Channel = #channel{will_msg = WillMsg, - timers = #{will_timer := TRef}}) -> +handle_timeout(_TRef, will_message, Channel = #channel{will_msg = WillMsg}) -> (WillMsg =/= undefined) andalso publish_will_msg(WillMsg), {ok, clean_timer(will_timer, Channel#channel{will_msg = undefined})}; diff --git a/src/emqx_connection.erl b/src/emqx_connection.erl index 774c0ba42..d0a923bff 100644 --- a/src/emqx_connection.erl +++ b/src/emqx_connection.erl @@ -459,17 +459,17 @@ handle_call(_From, Req, State = #state{channel = Channel}) -> %%-------------------------------------------------------------------- %% Handle timeout -handle_timeout(TRef, idle_timeout, State = #state{idle_timer = TRef}) -> +handle_timeout(_TRef, idle_timeout, State) -> shutdown(idle_timeout, State); -handle_timeout(TRef, limit_timeout, State = #state{limit_timer = TRef}) -> +handle_timeout(_TRef, limit_timeout, State) -> NState = State#state{sockstate = idle, limit_timer = undefined }, handle_info(activate_socket, NState); -handle_timeout(TRef, emit_stats, State = - #state{stats_timer = TRef, channel = Channel}) -> +handle_timeout(_TRef, emit_stats, State = + #state{channel = Channel}) -> ClientId = emqx_channel:info(clientid, Channel), emqx_cm:set_chan_stats(ClientId, stats(State)), {ok, State#state{stats_timer = undefined}};