Merge pull request #8349 from emqx/copy-of_main-v4.3

merge main-v4.3 into main-v4.4
This commit is contained in:
Xinyu Liu 2022-06-29 22:30:42 +08:00 committed by GitHub
commit 3c1251a99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 11 deletions

View File

@ -171,7 +171,7 @@ on_client_subscribe(#{clientid := ClientId, username := Username}, _Properties,
case on_client_subscribe_single(ClientId, Username, TopicFilter, LuaState) of case on_client_subscribe_single(ClientId, Username, TopicFilter, LuaState) of
false -> false ->
{Topic, Opts} = TopicFilter, {Topic, Opts} = TopicFilter,
[{Topic, Opts#{delete => true}} | Acc]; [{Topic, Opts#{deny_subscription => true}} | Acc];
NewTopicFilter -> NewTopicFilter ->
[NewTopicFilter | Acc] [NewTopicFilter | Acc]
end end

View File

@ -711,7 +711,7 @@ t_stop_sub(_Config) ->
OriginalTopicFilters = [{Topic = <<"u">>, OriginalTopicFilters = [{Topic = <<"u">>,
Opts = #{nl => 0,qos => 0,rap => 0,rh => 0}}], Opts = #{nl => 0,qos => 0,rap => 0,rh => 0}}],
Props = #{}, Props = #{},
Expected = [{Topic, Opts#{delete => true}}], Expected = [{Topic, Opts#{deny_subscription => true}}],
?assertEqual(Expected, emqx_hooks:run_fold('client.subscribe', ?assertEqual(Expected, emqx_hooks:run_fold('client.subscribe',
[ClientInfo, Props], [ClientInfo, Props],
OriginalTopicFilters)). OriginalTopicFilters)).

View File

@ -1,7 +1,10 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{VSN, {VSN,
[{<<".*">>, [{<<".*">>,
[{apply,{minirest,stop_http,['http:management']}}, [%% Stop the http listener to load the latest http handlers.
%% We can only stop these listeners here because we can't get the list of
%% currently started http listener via app-env during the hot upgrade.
{apply,{minirest,stop_http,['http:management']}},
{apply,{minirest,stop_http,['https:management']}}, {apply,{minirest,stop_http,['https:management']}},
{restart_application, emqx_management}]}], {restart_application, emqx_management}]}],
[{<<".*">>, [{<<".*">>,

View File

@ -85,6 +85,8 @@ listeners() ->
application:get_env(?APP, listeners, []). application:get_env(?APP, listeners, []).
listener_name(Proto) -> listener_name(Proto) ->
%% NOTE: this name has referenced by emqx_management.appup.src.
%% Please don't change it except you have got how to handle it in hot-upgrade
list_to_atom(atom_to_list(Proto) ++ ":management"). list_to_atom(atom_to_list(Proto) ++ ":management").
http_handlers() -> http_handlers() ->

View File

@ -29,7 +29,7 @@
-ifndef(EMQX_ENTERPRISE). -ifndef(EMQX_ENTERPRISE).
-define(EMQX_RELEASE, {opensource, "4.4.5-beta.3"}). -define(EMQX_RELEASE, {opensource, "4.4.5-beta.4"}).
-else. -else.

View File

@ -1,11 +1,21 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{VSN, {VSN,
[ {<<".*">>, [ {<<".*">>,
[ {restart_application, emqx_dashboard} [ %% Stop the http listener to load the latest http handlers.
%% We can only stop these listeners here because we can't get the list of
%% currently started http listener via app-env during the hot upgrade.
{apply, {minirest, stop_http, ['http:dashboard']}}
, {apply, {minirest, stop_http, ['https:dashboard']}}
, {restart_application, emqx_dashboard}
]} ]}
], ],
[ {<<".*">>, [ {<<".*">>,
[ {restart_application, emqx_dashboard} [ %% Stop the http listener to load the latest http handlers.
%% We can only stop these listeners here because we can't get the list of
%% currently started http listener via app-env during the hot upgrade.
{apply, {minirest, stop_http, ['http:dashboard']}}
, {apply, {minirest, stop_http, ['https:dashboard']}}
, {restart_application, emqx_dashboard}
]} ]}
] ]
}. }.

View File

@ -80,6 +80,8 @@ listeners() ->
application:get_env(?APP, listeners, []). application:get_env(?APP, listeners, []).
listener_name(Proto) -> listener_name(Proto) ->
%% NOTE: this name has referenced by emqx_dashboard.appup.src.
%% Please don't change it except you have got how to handle it in hot-upgrade
list_to_atom(atom_to_list(Proto) ++ ":dashboard"). list_to_atom(atom_to_list(Proto) ++ ":dashboard").
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View File

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

View File

@ -625,7 +625,7 @@ t_handle_in_empty_client_subscribe_hook({'end', _Config}) ->
ok; ok;
t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) -> t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
Hook = fun(_ClientInfo, _Username, TopicFilter) -> Hook = fun(_ClientInfo, _Username, TopicFilter) ->
EmptyFilters = [{T, Opts#{delete => true}} || {T, Opts} <- TopicFilter], EmptyFilters = [{T, Opts#{deny_subscription => true}} || {T, Opts} <- TopicFilter],
{stop, EmptyFilters} {stop, EmptyFilters}
end, end,
ok = emqx:hook('client.subscribe', Hook, []), ok = emqx:hook('client.subscribe', Hook, []),
@ -633,7 +633,7 @@ t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
{ok, C} = emqtt:start_link(), {ok, C} = emqtt:start_link(),
{ok, _} = emqtt:connect(C), {ok, _} = emqtt:connect(C),
{ok, _, RCs} = emqtt:subscribe(C, <<"t">>), {ok, _, RCs} = emqtt:subscribe(C, <<"t">>),
?assertEqual([], RCs), ?assertEqual([?RC_UNSPECIFIED_ERROR], RCs),
ok ok
after after
ok = emqx:unhook('client.subscribe', Hook) ok = emqx:unhook('client.subscribe', Hook)