fix: avoid logging unnecessary errors in async cleanup functions

Cleanup functions that access ETS tables may fail with `badarg` error during EMQX shutdown.
They are called asynchronously by `emqx_pool` workers and accessed ETS tables
may be already destroyed as their owners are shut down.
This fix catches ETS `badarg` errors before they can be caught and logged by `emqx_pool`.

Fixes: EMQX-9992
This commit is contained in:
Serge Tupchii 2023-07-14 14:22:43 +03:00
parent 0dff428efb
commit 950d5edc41
4 changed files with 24 additions and 11 deletions

View File

@ -153,6 +153,7 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
clean_down(SubPid) ->
try
case ets:lookup(?SUBMON, SubPid) of
[{_, SubId}] ->
true = ets:delete(?SUBMON, SubPid),
@ -162,4 +163,7 @@ clean_down(SubPid) ->
emqx_broker:subscriber_down(SubPid);
[] ->
ok
end
catch
error:badarg -> ok
end.

View File

@ -734,7 +734,11 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
clean_down({ChanPid, ClientId}) ->
do_unregister_channel({ClientId, ChanPid}),
try
do_unregister_channel({ClientId, ChanPid})
catch
error:badarg -> ok
end,
ok = ?tp(debug, emqx_cm_clean_down, #{client_id => ClientId}).
stats_fun() ->

View File

@ -823,7 +823,11 @@ code_change(_OldVsn, State, _Extra) ->
do_unregister_channel_task(Items, GwName, CmTabs) ->
lists:foreach(
fun({ChanPid, ClientId}) ->
try
do_unregister_channel(GwName, {ClientId, ChanPid}, CmTabs)
catch
error:badarg -> ok
end
end,
Items
).

View File

@ -0,0 +1 @@
Avoid logging irrelevant error messages during EMQX shutdown.