From 4f8a7349bfc7ae114e8fc9daa09d10fe95beb320 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sun, 9 Oct 2022 20:13:52 +0200 Subject: [PATCH] fix(shared): ensure sticky strategy sticks to the first pick Prior to this fix, the alive pids are never inserted due to a missing insert when handing remote pids from mnesia event. --- CHANGES-4.3.md | 7 +++++++ src/emqx_shared_sub.erl | 1 + 2 files changed, 8 insertions(+) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index c15ac220b..22a909780 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -64,6 +64,13 @@ File format: This issue only occurs when unsubscribe with the session kept. Fixed in [#9119](https://github.com/emqx/emqx/pull/9119) +- Fix shared subscription 'sticky' strategy when there is no local subscriptions at all. + Prior to this change, it may take a few rounds to randomly pick group members until a local subscriber + is hit (and then start sticking to it). + After this fix, it will start sticking to whichever randomly picked member even when it is a + subscriber from another node in the cluster. + Fixed in [#9122](https://github.com/emqx/emqx/pull/9122) + ## v4.3.20 ### Bug fixes diff --git a/src/emqx_shared_sub.erl b/src/emqx_shared_sub.erl index 65645c86a..9c051c62a 100644 --- a/src/emqx_shared_sub.erl +++ b/src/emqx_shared_sub.erl @@ -456,6 +456,7 @@ handle_cast(Msg, State) -> handle_info({mnesia_table_event, {write, NewRecord, _}}, State = #state{pmon = PMon}) -> #emqx_shared_subscription{subpid = SubPid} = NewRecord, + ok = maybe_insert_alive_tab(SubPid), {noreply, update_stats(State#state{pmon = emqx_pmon:monitor(SubPid, PMon)})}; %% The subscriber may have subscribed multiple topics, so we need to keep monitoring the PID until