From 1fc0f61fbbbf7576a301f61cf81633b66ff6f318 Mon Sep 17 00:00:00 2001 From: GilbertWong Date: Tue, 16 Jul 2019 01:09:42 +0800 Subject: [PATCH 1/2] Fix the websocket normal exit bug --- src/emqx_ws_channel.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/emqx_ws_channel.erl b/src/emqx_ws_channel.erl index 94ed70633..57cfd3cd6 100644 --- a/src/emqx_ws_channel.erl +++ b/src/emqx_ws_channel.erl @@ -315,9 +315,8 @@ terminate(SockError, _Req, #state{keepalive = Keepalive, emqx_protocol:terminate(Reason, ProtoState), exit(Reason); {_, Error} -> - ?LOG(error, "Unexpected terminated for ~p", [Error]), emqx_protocol:terminate(Error, ProtoState), - exit(unknown) + exit({error, Error}) end. %%-------------------------------------------------------------------- @@ -346,8 +345,8 @@ ensure_stats_timer(State) -> shutdown(Reason, State) -> %% Fix the issue#2591(https://github.com/emqx/emqx/issues/2591#issuecomment-500278696) - self() ! {stop, State#state{shutdown = {shutdown, Reason}}}, - {ok, State}. + self() ! {stop, {shutdown, Reason}}, + {ok, State#state{shutdown = {shutdown, Reason}}}. wsock_stats() -> [{Key, emqx_pd:get_counter(Key)} || Key <- ?SOCK_STATS]. From eb7ae13ae9de2ce87c5983ef20868c43199169d2 Mon Sep 17 00:00:00 2001 From: GilbertWong Date: Tue, 16 Jul 2019 01:33:15 +0800 Subject: [PATCH 2/2] Better exit reason in websocket channel --- src/emqx_ws_channel.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emqx_ws_channel.erl b/src/emqx_ws_channel.erl index 57cfd3cd6..9571baab8 100644 --- a/src/emqx_ws_channel.erl +++ b/src/emqx_ws_channel.erl @@ -316,7 +316,7 @@ terminate(SockError, _Req, #state{keepalive = Keepalive, exit(Reason); {_, Error} -> emqx_protocol:terminate(Error, ProtoState), - exit({error, Error}) + exit({error, SockError}) end. %%-------------------------------------------------------------------- @@ -346,7 +346,7 @@ ensure_stats_timer(State) -> shutdown(Reason, State) -> %% Fix the issue#2591(https://github.com/emqx/emqx/issues/2591#issuecomment-500278696) self() ! {stop, {shutdown, Reason}}, - {ok, State#state{shutdown = {shutdown, Reason}}}. + {ok, State}. wsock_stats() -> [{Key, emqx_pd:get_counter(Key)} || Key <- ?SOCK_STATS].