Forráskód Böngészése

fix(hooks): return error on hook-removed subscription rather than deleting it (5.0)

Port of https://github.com/emqx/emqx/pull/8346
Thales Macedo Garitezi 3 éve
szülő
commit
e70ab24a48

+ 3 - 3
apps/emqx/src/emqx_channel.erl

@@ -527,9 +527,9 @@ handle_in(
                     TupleTopicFilters2 =
                         lists:foldl(
                             fun
-                                ({{Topic, Opts = #{delete := true}}, _QoS}, Acc) ->
-                                    Key = {Topic, maps:without([delete], Opts)},
-                                    lists:keydelete(Key, 1, Acc);
+                                ({{Topic, Opts = #{deny_subscription := true}}, _QoS}, Acc) ->
+                                    Key = {Topic, maps:without([deny_subscription], Opts)},
+                                    lists:keyreplace(Key, 1, Acc, {Key, ?RC_UNSPECIFIED_ERROR});
                                 (Tuple = {Key, _Value}, Acc) ->
                                     lists:keyreplace(Key, 1, Acc, Tuple)
                             end,

+ 2 - 2
apps/emqx/test/emqx_broker_SUITE.erl

@@ -727,7 +727,7 @@ t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
     {ok, _} = emqtt:connect(C),
     try
         {ok, _, RCs} = emqtt:subscribe(C, <<"t">>),
-        ?assertEqual([], RCs),
+        ?assertEqual([?RC_UNSPECIFIED_ERROR], RCs),
         ok
     after
         emqtt:disconnect(C)
@@ -791,5 +791,5 @@ recv_msgs(Count, Msgs) ->
     end.
 
 client_subscribe_delete_all_hook(_ClientInfo, _Username, TopicFilter) ->
-    EmptyFilters = [{T, Opts#{delete => true}} || {T, Opts} <- TopicFilter],
+    EmptyFilters = [{T, Opts#{deny_subscription => true}} || {T, Opts} <- TopicFilter],
     {stop, EmptyFilters}.