Merge pull request #12740 from ieQu1/dev/kick-durable-sessions

fix(sessds): Channel must destroy sessions that are kicked
This commit is contained in:
ieQu1 2024-03-19 21:30:40 +01:00 committed by GitHub
commit 611e4f6710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

View File

@ -1146,9 +1146,11 @@ handle_call(
kick, kick,
Channel = #channel{ Channel = #channel{
conn_state = ConnState, conn_state = ConnState,
conninfo = #{proto_ver := ProtoVer} conninfo = #{proto_ver := ProtoVer},
session = Session
} }
) -> ) ->
emqx_session:destroy(Session),
Channel0 = maybe_publish_will_msg(kicked, Channel), Channel0 = maybe_publish_will_msg(kicked, Channel),
Channel1 = Channel1 =
case ConnState of case ConnState of

View File

@ -36,7 +36,8 @@
-export([ -export([
create/3, create/3,
open/3, open/3,
destroy/1 destroy/1,
kick_offline_session/1
]). ]).
-export([ -export([
@ -204,6 +205,14 @@ destroy(#{clientid := ClientID}) ->
destroy_session(ClientID) -> destroy_session(ClientID) ->
session_drop(ClientID, destroy). session_drop(ClientID, destroy).
kick_offline_session(ClientID) ->
emqx_cm_locker:trans(
ClientID,
fun(_Nodes) ->
session_drop(ClientID, kicked)
end
).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Info, Stats %% Info, Stats
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View File

@ -359,6 +359,10 @@ kickout_client(ClientId) ->
case lookup_client({clientid, ClientId}, undefined) of case lookup_client({clientid, ClientId}, undefined) of
[] -> [] ->
{error, not_found}; {error, not_found};
[{ClientId, _}] ->
%% Offline durable session (client ID is a plain binary
%% without channel pid):
emqx_persistent_session_ds:kick_offline_session(ClientId);
_ -> _ ->
Results = [kickout_client(Node, ClientId) || Node <- emqx:running_nodes()], Results = [kickout_client(Node, ClientId) || Node <- emqx:running_nodes()],
check_results(Results) check_results(Results)

View File

@ -0,0 +1 @@
Add support for kickout of durable sessions.