From 117c8197d72ff16b8b5cc0e8e71a29e5d8ad8849 Mon Sep 17 00:00:00 2001 From: firest Date: Wed, 24 Jul 2024 18:33:15 +0800 Subject: [PATCH 1/2] fix(exclusive): allow the same client to resubscribe to an existing exclusive topic --- apps/emqx/src/emqx_exclusive_subscription.erl | 7 +++++++ apps/emqx/test/emqx_exclusive_sub_SUITE.erl | 2 ++ 2 files changed, 9 insertions(+) diff --git a/apps/emqx/src/emqx_exclusive_subscription.erl b/apps/emqx/src/emqx_exclusive_subscription.erl index 3a9dc8014..095233fbb 100644 --- a/apps/emqx/src/emqx_exclusive_subscription.erl +++ b/apps/emqx/src/emqx_exclusive_subscription.erl @@ -117,6 +117,13 @@ try_subscribe(ClientId, Topic) -> write ), allow; + [#exclusive_subscription{clientid = ClientId, topic = Topic}] -> + %% Fixed the issue-13476 + %% In this feature, the user must manually call `unsubscribe` to release the lock, + %% but sometimes the node may go down for some reason, + %% then the client will reconnect to this node and resubscribe. + %% We need to allow resubscription, otherwise the lock will never be released. + allow; [_] -> deny end. diff --git a/apps/emqx/test/emqx_exclusive_sub_SUITE.erl b/apps/emqx/test/emqx_exclusive_sub_SUITE.erl index abbdb5f44..a859612b2 100644 --- a/apps/emqx/test/emqx_exclusive_sub_SUITE.erl +++ b/apps/emqx/test/emqx_exclusive_sub_SUITE.erl @@ -56,6 +56,8 @@ t_exclusive_sub(_) -> {ok, _} = emqtt:connect(C1), ?CHECK_SUB(C1, 0), + ?CHECK_SUB(C1, 0), + {ok, C2} = emqtt:start_link([ {clientid, <<"client2">>}, {clean_start, false}, From 4f21594707432a5f93dbe428d263b1585fc3dd54 Mon Sep 17 00:00:00 2001 From: firest Date: Wed, 24 Jul 2024 18:59:06 +0800 Subject: [PATCH 2/2] chore: update changes --- changes/ce/fix-13515.en.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/ce/fix-13515.en.md diff --git a/changes/ce/fix-13515.en.md b/changes/ce/fix-13515.en.md new file mode 100644 index 000000000..775c21848 --- /dev/null +++ b/changes/ce/fix-13515.en.md @@ -0,0 +1 @@ +Fixed an issue where the same client could not subscribe to the same exclusive topic when the node was down for some reason.