Skip to content

Commit

Permalink
Merge pull request #10571 from savonarola/0502-do-not-pullute-logs-on…
Browse files Browse the repository at this point in the history
…-metrics-stop

Do not complain on nonexisting ets while `emqx_topic_metrics` stops
  • Loading branch information
savonarola committed May 3, 2023
2 parents 8e7ba2b + 791010a commit 0272cf4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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.

0 comments on commit 0272cf4

Please sign in to comment.