Merge pull request #9091 from zmstone/1003-no-shutdown-logging-to-remote-node-when-rpc

fix(emqx): emqx:shutdown should not log to remote node
This commit is contained in:
Zaiming (Stone) Shi 2022-10-11 08:12:28 +02:00 committed by GitHub
commit 124f9795cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -227,6 +227,7 @@ shutdown() ->
shutdown(normal).
shutdown(Reason) ->
ok = emqx_misc:maybe_mute_rpc_log(),
?LOG(critical, "emqx shutdown for ~s", [Reason]),
on_shutdown(Reason),
_ = emqx_plugins:unload(),

View File

@ -23,6 +23,7 @@
-export([ merge_opts/2
, maybe_apply/2
, maybe_mute_rpc_log/0
, compose/1
, compose/2
, run_fold/3
@ -444,6 +445,27 @@ do_parallel_map(Fun, List) ->
PidList
).
%% @doc Call this function to avoid logs printed to RPC caller node.
-spec maybe_mute_rpc_log() -> ok.
maybe_mute_rpc_log() ->
GlNode = node(group_leader()),
maybe_mute_rpc_log(GlNode).
maybe_mute_rpc_log(Node) when Node =:= node() ->
%% do nothing, this is a local call
ok;
maybe_mute_rpc_log(Node) ->
case atom_to_list(Node) of
"remsh_" ++ _ ->
%% this is either an upgrade script or nodetool
%% do nothing, the log may go to the 'emqx' command line console
ok;
_ ->
%% otherwise set group leader to local node
_ = group_leader(whereis(init), self()),
ok
end.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").