From a564670863243fc393df5b7d1222fc8916e4f052 Mon Sep 17 00:00:00 2001 From: z8674558 Date: Thu, 17 Dec 2020 15:57:38 +0900 Subject: [PATCH] fix(coap): fix the issue the connection with same clientid is not discarded --- apps/emqx_coap/src/emqx_coap_mqtt_adapter.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/emqx_coap/src/emqx_coap_mqtt_adapter.erl b/apps/emqx_coap/src/emqx_coap_mqtt_adapter.erl index fc4e5c60c..6ce30a9e6 100644 --- a/apps/emqx_coap/src/emqx_coap_mqtt_adapter.erl +++ b/apps/emqx_coap/src/emqx_coap_mqtt_adapter.erl @@ -111,12 +111,12 @@ init({ClientId, Username, Password, Channel}) -> _ = run_hooks('client.connect', [conninfo(State0)], undefined), case emqx_access_control:authenticate(clientinfo(State0)) of {ok, _AuthResult} -> + ok = emqx_cm:discard_session(ClientId), + _ = run_hooks('client.connack', [conninfo(State0), success], undefined), State = State0#state{connected_at = erlang:system_time(millisecond)}, - %% TODO: Evict same clientid on other node?? - run_hooks('client.connected', [clientinfo(State), conninfo(State)]), erlang:send_after(?ALIVE_INTERVAL, self(), check_alive), @@ -186,6 +186,11 @@ handle_info({shutdown, conflict, {ClientId, NewPid}}, State) -> ?LOG(warning, "clientid '~s' conflict with ~p", [ClientId, NewPid]), {stop, {shutdown, conflict}, State}; +handle_info(discard, State) -> + ?LOG(warning, "the connection is discarded. " ++ + "possibly there is another client with the same clientid", []), + {stop, {shutdown, discarded}, State}; + handle_info(kick, State) -> ?LOG(info, "Kicked", []), {stop, {shutdown, kick}, State};