diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index 26dd529a2..c15ac220b 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -58,6 +58,12 @@ File format: - For wildcard deliveries, the re-dispatch used the wrong topic (the publishing topic, but not the subscribing topic), caused messages to be lost when dispatching. +- Fix shared subscription group member unsubscribe issue when 'sticky' strategy is used. + Prior to this fix, if a previously picked member unsubscribes from the group (without reconnect) + the message is still dispatched to it. + This issue only occurs when unsubscribe with the session kept. + Fixed in [#9119](https://github.com/emqx/emqx/pull/9119) + ## v4.3.20 ### Bug fixes diff --git a/src/emqx_shared_sub.erl b/src/emqx_shared_sub.erl index 6130ccc0a..65645c86a 100644 --- a/src/emqx_shared_sub.erl +++ b/src/emqx_shared_sub.erl @@ -337,7 +337,8 @@ fetch_sender_ref({Sender, Ref}) -> {Sender, Ref}. pick(sticky, ClientId, SourceTopic, Group, Topic, FailedSubs) -> Sub0 = erlang:get({shared_sub_sticky, Group, Topic}), - case is_active_sub(Sub0, FailedSubs) of + All = subscribers(Group, Topic), + case is_active_sub(Sub0, FailedSubs, All) of true -> %% the old subscriber is still alive %% keep using it for sticky strategy @@ -507,8 +508,10 @@ update_stats(State) -> State. %% Return 'true' if the subscriber process is alive AND not in the failed list -is_active_sub(Pid, FailedSubs) -> - not maps:is_key(Pid, FailedSubs) andalso is_alive_sub(Pid). +is_active_sub(Pid, FailedSubs, All) -> + lists:member(Pid, All) andalso + (not maps:is_key(Pid, FailedSubs)) andalso + is_alive_sub(Pid). %% erlang:is_process_alive/1 does not work with remote pid. is_alive_sub(Pid) when ?IS_LOCAL_PID(Pid) ->