Skip to content

Commit 34bcb91

Browse files
committed
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.
1 parent 58d4e75 commit 34bcb91

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

deps/rabbit/src/rabbit_logger_exchange_h.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ log(#{meta := #{mfa := {?MODULE, _, _}}}, _) ->
4444
ok;
4545
log(LogEvent, Config) ->
4646
case rabbit_boot_state:get() of
47-
ready -> do_log(LogEvent, Config);
48-
_ -> ok
47+
ready ->
48+
try
49+
do_log(LogEvent, Config)
50+
catch
51+
C:R:S ->
52+
%% don't let logging crash, because then OTP logger
53+
%% removes the logger_exchange handler, which in
54+
%% turn deletes the log exchange and its bindings
55+
erlang:display({?MODULE, crashed, {C, R, S}})
56+
end,
57+
ok;
58+
_ -> ok
4959
end.
5060

5161
do_log(LogEvent, #{config := #{exchange := Exchange}} = Config) ->

0 commit comments

Comments
 (0)