Skip to content

Commit 090b33a

Browse files
gomoripetimergify[bot]
authored andcommitted
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. (cherry picked from commit 34bcb91) (cherry picked from commit 2d2e79d)
1 parent 73b7388 commit 090b33a

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
@@ -46,8 +46,18 @@ log(#{meta := #{mfa := {?MODULE, _, _}}}, _) ->
4646
ok;
4747
log(LogEvent, Config) ->
4848
case rabbit_boot_state:get() of
49-
ready -> do_log(LogEvent, Config);
50-
_ -> ok
49+
ready ->
50+
try
51+
do_log(LogEvent, Config)
52+
catch
53+
C:R:S ->
54+
%% don't let logging crash, because then OTP logger
55+
%% removes the logger_exchange handler, which in
56+
%% turn deletes the log exchange and its bindings
57+
erlang:display({?MODULE, crashed, {C, R, S}})
58+
end,
59+
ok;
60+
_ -> ok
5161
end.
5262

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

0 commit comments

Comments
 (0)