Skip to content

Commit

Permalink
Fix unexpected timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercl authored and turtleDeng committed Dec 30, 2019
1 parent 7f807c0 commit 597558f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
20 changes: 8 additions & 12 deletions src/emqx_channel.erl
Expand Up @@ -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},
Expand All @@ -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})};
Expand All @@ -811,21 +809,19 @@ 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})};
{ok, Timeout, Session} ->
{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})};

Expand Down
8 changes: 4 additions & 4 deletions src/emqx_connection.erl
Expand Up @@ -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}};
Expand Down

0 comments on commit 597558f

Please sign in to comment.