Skip to content

Commit 8a3cd92

Browse files
committed
Terminate when ra_systems_sup exits
The goal of this change is to shut down Rabbit when the `ra_systems_sup` supervisor exits. If disk is completely exhausted then the `ra_systems_sup` supervisor can exit from the repeated `enospc` errors. If we do not also crash Rabbit, Rabbit continues on but Khepri is unavailable, so no incoming connections can successfully log in. Plus there are other effects like `rabbit_vhost_process` deleting a vhost because Khepri does not say that it exists.
1 parent 3bffa63 commit 8a3cd92

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

deps/rabbit/src/rabbit_ra_systems.erl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
-module(rabbit_ra_systems).
99

10+
-behaviour(gen_server).
11+
1012
-include_lib("kernel/include/logger.hrl").
1113

1214
-include_lib("rabbit_common/include/logging.hrl").
@@ -20,6 +22,21 @@
2022
ensure_started/0,
2123
ensure_stopped/0]).
2224

25+
-export([start_link/0,
26+
init/1,
27+
handle_call/3,
28+
handle_cast/2,
29+
handle_info/2,
30+
terminate/2,
31+
code_change/3]).
32+
-export([stop/0]).
33+
34+
-rabbit_boot_step({rabbit_ra_systems_monitor,
35+
[{description, "monitor process to shut down when Ra systems exit"},
36+
{mfa, {rabbit_sup, start_child, [?MODULE]}},
37+
{requires, [kernel_ready]},
38+
{cleanup, {?MODULE, stop, []}}]}).
39+
2340
-type ra_system_name() :: atom().
2441

2542
-define(COORD_WAL_MAX_SIZE_B, 64_000_000).
@@ -192,3 +209,38 @@ ensure_ra_system_stopped(RaSystem) ->
192209
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
193210
throw(Error)
194211
end.
212+
213+
%% ----------------------------------------------------------------------------
214+
215+
start_link() ->
216+
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
217+
218+
stop() ->
219+
case supervisor:terminate_child(rabbit_sup, ?MODULE) of
220+
ok -> ok = supervisor:delete_child(rabbit_sup, ?MODULE);
221+
{error, not_found} -> ok
222+
end.
223+
224+
init(_) ->
225+
process_flag(trap_exit, true),
226+
Pid = whereis(ra_systems_sup),
227+
true = link(Pid),
228+
{ok, Pid, hibernate}.
229+
230+
handle_call(_Request, _From, State) -> {noreply, State}.
231+
232+
handle_cast(_Msg, State) -> {noreply, State}.
233+
234+
handle_info({'EXIT', RaSystemsSup, Reason} = E, RaSystemsSup) ->
235+
?LOG_ERROR(
236+
?MODULE_STRING ": Ra system supervisor exited with reason ~tp~n",
237+
[Reason],
238+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
239+
exit(E);
240+
handle_info(_Info, State) -> {noreply, State}.
241+
242+
terminate(_, RaSystemsSup) ->
243+
true = unlink(RaSystemsSup),
244+
ok.
245+
246+
code_change(_OldVsn, State, _Extra) -> {ok, State}.

0 commit comments

Comments
 (0)