Merge pull request #2835 from emqx/fix-discard

Handle the 'discard' cast.
This commit is contained in:
tigercl 2019-08-23 14:41:22 +08:00 committed by GitHub
commit b924825fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -310,6 +310,9 @@ handle({call, From}, Req, State = #state{chan_state = ChanState}) ->
stop(Reason, State#state{chan_state = NChanState}) stop(Reason, State#state{chan_state = NChanState})
end; end;
handle(cast, discard, State) ->
shutdown(discarded, State);
%% Handle cast %% Handle cast
handle(cast, Msg, State = #state{chan_state = ChanState}) -> handle(cast, Msg, State = #state{chan_state = ChanState}) ->
case emqx_channel:handle_cast(Msg, ChanState) of case emqx_channel:handle_cast(Msg, ChanState) of

View File

@ -244,6 +244,9 @@ websocket_info({call, From, Req}, State = #state{chan_state = ChanState}) ->
stop(Reason, State#state{chan_state = NChanState}) stop(Reason, State#state{chan_state = NChanState})
end; end;
websocket_info({cast, discard}, State) ->
stop(discarded, State);
websocket_info({cast, Msg}, State = #state{chan_state = ChanState}) -> websocket_info({cast, Msg}, State = #state{chan_state = ChanState}) ->
case emqx_channel:handle_cast(Msg, ChanState) of case emqx_channel:handle_cast(Msg, ChanState) of
{ok, NChanState} -> {ok, NChanState} ->
@ -295,10 +298,6 @@ websocket_info({timeout, TRef, emit_stats}, State) when is_reference(TRef) ->
websocket_info({timeout, TRef, Msg}, State) when is_reference(TRef) -> websocket_info({timeout, TRef, Msg}, State) when is_reference(TRef) ->
handle_timeout(TRef, Msg, State); handle_timeout(TRef, Msg, State);
websocket_info({shutdown, discard, {ClientId, ByPid}}, State) ->
?LOG(warning, "Discarded by ~s:~p", [ClientId, ByPid]),
stop(discard, State);
websocket_info({shutdown, conflict, {ClientId, NewPid}}, State) -> websocket_info({shutdown, conflict, {ClientId, NewPid}}, State) ->
?LOG(warning, "Clientid '~s' conflict with ~p", [ClientId, NewPid]), ?LOG(warning, "Clientid '~s' conflict with ~p", [ClientId, NewPid]),
stop(conflict, State); stop(conflict, State);