Skip to content

Commit f0da426

Browse files
author
Daniil Fedotov
committed
Call init:stop() during rabbitmqctl stop even if logging fails.
This makes sure that we try to stop an erlang app even if an exception is thrown during logging in the "after" block. Otherwise there is an inconsistency between "failed and the erlang node will stop" and "failed, but the erlang node will not stop"
1 parent 0b03088 commit f0da426

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/rabbit.erl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,21 @@ stop_and_halt() ->
450450
rabbit_log:error("Error trying to stop RabbitMQ: ~p:~p", [Type, Reason]),
451451
error({Type, Reason})
452452
after
453-
AppsLeft = [ A || {A, _, _} <- application:which_applications() ],
454-
rabbit_log:info(
455-
lists:flatten(["Halting Erlang VM with the following applications:~n",
456-
[" ~p~n" || _ <- AppsLeft]]),
457-
AppsLeft),
458-
%% Also duplicate this information to stderr, so console where
459-
%% foreground broker was running (or systemd journal) will
460-
%% contain information about graceful termination.
461-
io:format(standard_error, "Gracefully halting Erlang VM~n", []),
462-
init:stop()
453+
%% Enclose all the logging in the try block.
454+
%% init:stop() will be called regardless of any errors.
455+
try
456+
AppsLeft = [ A || {A, _, _} <- application:which_applications() ],
457+
rabbit_log:info(
458+
lists:flatten(["Halting Erlang VM with the following applications:~n",
459+
[" ~p~n" || _ <- AppsLeft]]),
460+
AppsLeft),
461+
%% Also duplicate this information to stderr, so console where
462+
%% foreground broker was running (or systemd journal) will
463+
%% contain information about graceful termination.
464+
io:format(standard_error, "Gracefully halting Erlang VM~n", [])
465+
after
466+
init:stop()
467+
end
463468
end,
464469
ok.
465470

0 commit comments

Comments
 (0)