Fix the crash caused by keepalive:start/3

This commit is contained in:
Feng Lee 2017-03-13 12:42:02 +08:00
parent 0df59934c7
commit 90e46325df
3 changed files with 12 additions and 7 deletions

View File

@ -252,7 +252,7 @@ handle_info({keepalive, start, Interval}, State = #client_state{connection = Con
{error, Error} -> {error, Error} {error, Error} -> {error, Error}
end end
end, end,
case emqttd_keepalive:start(StatFun, Interval, {keepalive, check}) of case emqttd_keepalive:start(Statfun, Interval, {keepalive, check}) of
{ok, KeepAlive} -> {ok, KeepAlive} ->
{noreply, State#client_state{keepalive = KeepAlive}, hibernate}; {noreply, State#client_state{keepalive = KeepAlive}, hibernate};
{error, Error} -> {error, Error} ->
@ -379,3 +379,4 @@ stop(Reason, State) ->
gc(State) -> gc(State) ->
emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State). emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State).

View File

@ -64,8 +64,7 @@ resume(KeepAlive = #keepalive{tsec = TimeoutSec, tmsg = TimeoutMsg}) ->
%% @doc Cancel Keepalive %% @doc Cancel Keepalive
-spec(cancel(keepalive()) -> ok). -spec(cancel(keepalive()) -> ok).
cancel(#keepalive{tref = TRef}) when is_reference(TRef) -> cancel(#keepalive{tref = TRef}) when is_reference(TRef) ->
erlang:cancel_timer(TRef), catch erlang:cancel_timer(TRef), ok;
ok;
cancel(_) -> cancel(_) ->
ok. ok.

View File

@ -198,8 +198,13 @@ handle_info({shutdown, conflict, {ClientId, NewPid}}, State) ->
handle_info({keepalive, start, Interval}, State = #wsclient_state{connection = Conn}) -> handle_info({keepalive, start, Interval}, State = #wsclient_state{connection = Conn}) ->
?WSLOG(debug, "Keepalive at the interval of ~p", [Interval], State), ?WSLOG(debug, "Keepalive at the interval of ~p", [Interval], State),
KeepAlive = emqttd_keepalive:start(stat_fun(Conn), Interval, {keepalive, check}), case emqttd_keepalive:start(stat_fun(Conn), Interval, {keepalive, check}) of
{ok, KeepAlive} ->
{noreply, State#wsclient_state{keepalive = KeepAlive}, hibernate}; {noreply, State#wsclient_state{keepalive = KeepAlive}, hibernate};
{error, Error} ->
?LOG(warning, "Keepalive error - ~p", [Error], State),
shutdown(Error, State)
end;
handle_info({keepalive, check}, State = #wsclient_state{keepalive = KeepAlive}) -> handle_info({keepalive, check}, State = #wsclient_state{keepalive = KeepAlive}) ->
case emqttd_keepalive:check(KeepAlive) of case emqttd_keepalive:check(KeepAlive) of