Skip to content

Commit

Permalink
Merge pull request #11733 from keynslug/fix/EMQX-10827/sesson-takeover
Browse files Browse the repository at this point in the history
fix(cm): bring back pre-v5.3.0 compat in `takeover_session_begin/1`
  • Loading branch information
zmstone committed Oct 10, 2023
2 parents ee45145 + 6301294 commit a2e86c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions apps/emqx/src/emqx_cm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ takeover_session_begin(ClientId) ->

takeover_session_begin(ClientId, ChanPid) when is_pid(ChanPid) ->
case takeover_session(ClientId, ChanPid) of
{living, ConnMod, Session} ->
{living, ConnMod, ChanPid, Session} ->
{ok, Session, {ConnMod, ChanPid}};
none ->
_ ->
none
end;
takeover_session_begin(_ClientId, undefined) ->
Expand Down Expand Up @@ -368,13 +368,20 @@ do_takeover_begin(ClientId, ChanPid) when node(ChanPid) == node() ->
ConnMod when is_atom(ConnMod) ->
case request_stepdown({takeover, 'begin'}, ConnMod, ChanPid) of
{ok, Session} ->
{living, ConnMod, Session};
{living, ConnMod, ChanPid, Session};
{error, Reason} ->
error(Reason)
end
end;
do_takeover_begin(ClientId, ChanPid) ->
wrap_rpc(emqx_cm_proto_v2:takeover_session(ClientId, ChanPid)).
case wrap_rpc(emqx_cm_proto_v2:takeover_session(ClientId, ChanPid)) of
%% NOTE: v5.3.0
{living, ConnMod, Session} ->
{living, ConnMod, ChanPid, Session};
%% NOTE: other versions
Res ->
Res
end.

%% @doc Discard all the sessions identified by the ClientId.
-spec discard_session(emqx_types:clientid()) -> ok.
Expand Down
4 changes: 3 additions & 1 deletion apps/emqx/src/proto/emqx_cm_proto_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ get_chann_conn_mod(ClientId, ChanPid) ->

-spec takeover_session(emqx_types:clientid(), emqx_cm:chan_pid()) ->
none
| {expired | persistent, emqx_session:session()}
| {living, _ConnMod :: atom(), emqx_cm:chan_pid(), emqx_session:session()}
%% NOTE: v5.3.0
| {living, _ConnMod :: atom(), emqx_session:session()}
| {expired | persistent, emqx_session:session()}
| {badrpc, _}.
takeover_session(ClientId, ChanPid) ->
rpc:call(node(ChanPid), emqx_cm, takeover_session, [ClientId, ChanPid], ?T_TAKEOVER * 2).
Expand Down
1 change: 1 addition & 0 deletions changes/ee/fix-11733.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolved an incompatibility issue that led to crashes during session takeover / channel eviction when the session was residing on a remote node running EMQX v5.2.x or earlier.

0 comments on commit a2e86c6

Please sign in to comment.