From d8cbf72da1b07bebefb613d61e36152126f7a1f3 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 12 Dec 2018 16:32:58 +0800 Subject: [PATCH] Fix 'badarg' crash --- src/emqx_session.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/emqx_session.erl b/src/emqx_session.erl index b92baa567..4f0743210 100644 --- a/src/emqx_session.erl +++ b/src/emqx_session.erl @@ -648,11 +648,14 @@ handle_info(Info, State) -> terminate(Reason, #state{will_msg = WillMsg, conn_pid = ConnPid}) -> %% Should not run hooks here. %% emqx_hooks:run('session.terminated', [#{client_id => ClientId}, Reason]), + %% Let it crash. + %% emqx_sm:unregister_session(ClientId), send_willmsg(WillMsg), %% Ensure to shutdown the connection - (ConnPid =:= undefined) orelse ConnPid ! {shutdown, Reason}. - %% Let it crash. - %% emqx_sm:unregister_session(ClientId). + if + ConnPid == undefined -> ok; + true -> ConnPid ! {shutdown, Reason} + end. code_change(_OldVsn, State, _Extra) -> {ok, State}.