From cdf42760fac7a35f510a82623e3cf0141c12c5b3 Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 17 May 2023 11:01:03 +0200 Subject: [PATCH] chore: little change avoid atom leak --- apps/emqx/src/emqx_shared_sub.erl | 29 ++++++++++++------------ apps/emqx_authn/src/emqx_authn_api.erl | 4 ++-- apps/emqx_bridge/src/emqx_bridge_api.erl | 6 ++++- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/emqx/src/emqx_shared_sub.erl b/apps/emqx/src/emqx_shared_sub.erl index 194e99999..bc13a06c6 100644 --- a/apps/emqx/src/emqx_shared_sub.erl +++ b/apps/emqx/src/emqx_shared_sub.erl @@ -158,20 +158,18 @@ dispatch(Group, Topic, Delivery = #delivery{message = Msg}, FailedSubs) -> -spec strategy(emqx_topic:group()) -> strategy(). strategy(Group) -> - case - emqx:get_config( - [ - broker, - shared_subscription_group, - %%binary_to_existing_atom(Group, utf8), - binary_to_atom(Group), - strategy - ], - undefined - ) - of - undefined -> emqx:get_config([broker, shared_subscription_strategy]); - Strategy -> Strategy + try + emqx:get_config([ + broker, + shared_subscription_group, + binary_to_existing_atom(Group), + strategy + ]) + catch + error:{config_not_found, _} -> + get_default_shared_subscription_strategy(); + error:badarg -> + get_default_shared_subscription_strategy() end. -spec ack_enabled() -> boolean(). @@ -555,3 +553,6 @@ delete_route_if_needed({Group, Topic} = GroupTopic) -> if_no_more_subscribers(GroupTopic, fun() -> ok = emqx_router:do_delete_route(Topic, {Group, node()}) end). + +get_default_shared_subscription_strategy() -> + emqx:get_config([broker, shared_subscription_strategy]). diff --git a/apps/emqx_authn/src/emqx_authn_api.erl b/apps/emqx_authn/src/emqx_authn_api.erl index 8ce3eadf2..f00ca8ed1 100644 --- a/apps/emqx_authn/src/emqx_authn_api.erl +++ b/apps/emqx_authn/src/emqx_authn_api.erl @@ -794,8 +794,8 @@ find_authenticator_config(AuthenticatorID, ConfKeyPath) -> with_listener(ListenerID, Fun) -> case find_listener(ListenerID) of {ok, {BType, BName}} -> - Type = binary_to_existing_atom(BType, utf8), - Name = binary_to_existing_atom(BName, utf8), + Type = binary_to_existing_atom(BType), + Name = binary_to_existing_atom(BName), ChainName = binary_to_atom(ListenerID), Fun(Type, Name, ChainName); {error, Reason} -> diff --git a/apps/emqx_bridge/src/emqx_bridge_api.erl b/apps/emqx_bridge/src/emqx_bridge_api.erl index e7a1282ce..7a6eb5120 100644 --- a/apps/emqx_bridge/src/emqx_bridge_api.erl +++ b/apps/emqx_bridge/src/emqx_bridge_api.erl @@ -687,11 +687,15 @@ get_metrics_from_local_node(BridgeType, BridgeName) -> ). is_enabled_bridge(BridgeType, BridgeName) -> - try emqx:get_config([bridges, BridgeType, binary_to_atom(BridgeName)]) of + try emqx:get_config([bridges, BridgeType, binary_to_existing_atom(BridgeName)]) of ConfMap -> maps:get(enable, ConfMap, false) catch error:{config_not_found, _} -> + throw(not_found); + error:badarg -> + %% catch non-existing atom, + %% none-existing atom means it is not available in config PT storage. throw(not_found) end.