Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not complain on nonexisting ets while emqx_topic_metrics stops #10571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/emqx_modules/src/emqx_modules.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_modules, [
{description, "EMQX Modules"},
{vsn, "5.0.13"},
{vsn, "5.0.14"},
{modules, []},
{applications, [kernel, stdlib, emqx, emqx_ctl]},
{mod, {emqx_modules_app, []}},
Expand Down
7 changes: 6 additions & 1 deletion apps/emqx_modules/src/emqx_topic_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ deregister_all() ->
gen_server:call(?MODULE, {deregister, all}).

is_registered(Topic) ->
ets:member(?TAB, Topic).
try
ets:member(?TAB, Topic)
catch
error:badarg ->
false
end.

all_registered_topics() ->
[Topic || {Topic, _} <- ets:tab2list(?TAB)].
Expand Down
10 changes: 10 additions & 0 deletions apps/emqx_modules/test/emqx_topic_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ init_per_testcase(_Case, Config) ->
emqx_topic_metrics:deregister_all(),
Config.

end_per_testcase(t_metrics_not_started, _Config) ->
_ = supervisor:restart_child(emqx_modules_sup, emqx_topic_metrics),
ok;
end_per_testcase(_Case, _Config) ->
emqx_topic_metrics:deregister_all(),
emqx_config:put([topic_metrics], []),
Expand Down Expand Up @@ -181,3 +184,10 @@ t_unknown_messages(_) ->
OldPid,
whereis(emqx_topic_metrics)
).

t_metrics_not_started(_Config) ->
_ = emqx_topic_metrics:register(<<"a/b/c">>),
?assert(emqx_topic_metrics:is_registered(<<"a/b/c">>)),
ok = supervisor:terminate_child(emqx_modules_sup, emqx_topic_metrics),
?assertNot(emqx_topic_metrics:is_registered(<<"a/b/c">>)),
{ok, _} = supervisor:restart_child(emqx_modules_sup, emqx_topic_metrics).
2 changes: 2 additions & 0 deletions changes/ce/feat-10571.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Do not emit useless crash report when EMQX stops.
Previously, when EMQX (and `emqx_topic_metrics` in particular) stopped and removed underlying tables, some messages were still being handled and crashed.