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

View File

@ -36,8 +36,8 @@ start(StatFun, TimeoutSec, TimeoutMsg) ->
case StatFun() of
{ok, StatVal} ->
{ok, #keepalive{statfun = StatFun, statval = StatVal,
tsec = TimeoutSec, tmsg = TimeoutMsg,
tref = timer(TimeoutSec, TimeoutMsg)}};
tsec = TimeoutSec, tmsg = TimeoutMsg,
tref = timer(TimeoutSec, TimeoutMsg)}};
{error, Error} ->
{error, Error}
end.
@ -64,8 +64,7 @@ resume(KeepAlive = #keepalive{tsec = TimeoutSec, tmsg = TimeoutMsg}) ->
%% @doc Cancel Keepalive
-spec(cancel(keepalive()) -> ok).
cancel(#keepalive{tref = TRef}) when is_reference(TRef) ->
erlang:cancel_timer(TRef),
ok;
catch erlang:cancel_timer(TRef), ok;
cancel(_) ->
ok.

View File

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