diff --git a/src/emqttd_ws_client.erl b/src/emqttd_ws_client.erl index 1fc9fa60f..12968dceb 100644 --- a/src/emqttd_ws_client.erl +++ b/src/emqttd_ws_client.erl @@ -62,6 +62,7 @@ unsubscribe(CPid, Topics) -> %%-------------------------------------------------------------------- init([MqttEnv, WsPid, Req, ReplyChannel]) -> + process_flag(trap_exit, true), true = link(WsPid), {ok, Peername} = Req:get(peername), Headers = mochiweb_headers:to_list( @@ -171,6 +172,13 @@ handle_info({keepalive, check}, State = #wsclient_state{peer = Peer, shutdown(keepalive_error, State) end; +handle_info({'EXIT', WsPid, normal}, State = #wsclient_state{ws_pid = WsPid}) -> + stop(normal, State); + +handle_info({'EXIT', WsPid, Reason}, State = #wsclient_state{peer = Peer, ws_pid = WsPid}) -> + ?WSLOG(error, Peer, "shutdown: ~p",[Reason]), + shutdown(Reason, State); + handle_info(Info, State = #wsclient_state{peer = Peer}) -> ?WSLOG(critical, Peer, "Unexpected Info: ~p", [Info]), noreply(State).