Fix the ws channel terminating crash when session pid is undefined
This commit is contained in:
parent
391e39c3b6
commit
eb68ce77b6
|
@ -312,20 +312,25 @@ terminate(WsReason, _Req, #state{keepalive = Keepalive,
|
||||||
case {ProtoState, Shutdown} of
|
case {ProtoState, Shutdown} of
|
||||||
{undefined, _} -> ok;
|
{undefined, _} -> ok;
|
||||||
{_, {shutdown, Reason}} ->
|
{_, {shutdown, Reason}} ->
|
||||||
SessionPid = emqx_protocol:session(ProtoState),
|
terminate_session(Reason, ProtoState);
|
||||||
emqx_protocol:terminate(Reason, ProtoState),
|
|
||||||
SessionPid ! {'EXIT', self(), Reason};
|
|
||||||
{_, _Error} ->
|
{_, _Error} ->
|
||||||
?LOG(info, "Terminate for unexpected error: ~p", [WsReason]),
|
?LOG(info, "Terminate for unexpected error: ~p", [WsReason]),
|
||||||
SessionPid = emqx_protocol:session(ProtoState),
|
terminate_session(unknown, ProtoState)
|
||||||
emqx_protocol:terminate(unknown, ProtoState),
|
|
||||||
SessionPid ! {'EXIT', self(), unknown}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
terminate_session(Reason, ProtoState) ->
|
||||||
|
emqx_protocol:terminate(Reason, ProtoState),
|
||||||
|
case emqx_protocol:session(ProtoState) of
|
||||||
|
undefined ->
|
||||||
|
ok;
|
||||||
|
SessionPid ->
|
||||||
|
SessionPid ! {'EXIT', self(), Reason}
|
||||||
|
end.
|
||||||
|
|
||||||
handle_incoming(Packet, SuccFun, State = #state{proto_state = ProtoState}) ->
|
handle_incoming(Packet, SuccFun, State = #state{proto_state = ProtoState}) ->
|
||||||
case emqx_protocol:received(Packet, ProtoState) of
|
case emqx_protocol:received(Packet, ProtoState) of
|
||||||
{ok, NProtoState} ->
|
{ok, NProtoState} ->
|
||||||
|
|
Loading…
Reference in New Issue