Prevent exchange logging crash

Don't let the `log` callback of exchange_logging handler crash,
because in case of a crash OTP logger removes the exchange_logger
handler, which in turn deletes the log exchange and its bindings.

It was seen several times in production that the log exchange suddenly
disappears and without debug logging there is no trace of why.

With this commit `erlang:display` will print the reason and stacktrace
to stderr without using the logging infrastructure.
This commit is contained in:
Péter Gömöri 2024-08-23 00:28:10 +02:00
parent 58d4e753ee
commit 34bcb91159
1 changed files with 12 additions and 2 deletions

View File

@ -44,8 +44,18 @@ log(#{meta := #{mfa := {?MODULE, _, _}}}, _) ->
ok;
log(LogEvent, Config) ->
case rabbit_boot_state:get() of
ready -> do_log(LogEvent, Config);
_ -> ok
ready ->
try
do_log(LogEvent, Config)
catch
C:R:S ->
%% don't let logging crash, because then OTP logger
%% removes the logger_exchange handler, which in
%% turn deletes the log exchange and its bindings
erlang:display({?MODULE, crashed, {C, R, S}})
end,
ok;
_ -> ok
end.
do_log(LogEvent, #{config := #{exchange := Exchange}} = Config) ->