Skip to content

Commit 56ddbbd

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 34df56a commit 56ddbbd

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

deps/rabbit/src/rabbit_ra_systems.erl

Lines changed: 47 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,20 @@
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+
code_change/3]).
31+
-export([stop/0]).
32+
33+
-rabbit_boot_step({rabbit_ra_systems_monitor,
34+
[{description, "monitor process to shut down when Ra systems exit"},
35+
{mfa, {rabbit_sup, start_child, [?MODULE]}},
36+
{requires, [kernel_ready]},
37+
{cleanup, {?MODULE, stop, []}}]}).
38+
2339
-type ra_system_name() :: atom().
2440

2541
-define(COORD_WAL_MAX_SIZE_B, 64_000_000).
@@ -187,3 +203,34 @@ ensure_ra_system_stopped(RaSystem) ->
187203
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
188204
throw(Error)
189205
end.
206+
207+
%% ----------------------------------------------------------------------------
208+
209+
start_link() ->
210+
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
211+
212+
stop() ->
213+
case supervisor:terminate_child(rabbit_sup, ?MODULE) of
214+
ok -> ok = supervisor:delete_child(rabbit_sup, ?MODULE);
215+
{error, not_found} -> ok
216+
end.
217+
218+
init(_) ->
219+
process_flag(trap_exit, true),
220+
Pid = whereis(ra_systems_sup),
221+
true = link(Pid),
222+
{ok, Pid, hibernate}.
223+
224+
handle_call(_Request, _From, State) -> {noreply, State}.
225+
226+
handle_cast(_Msg, State) -> {noreply, State}.
227+
228+
handle_info({'EXIT', RaSystemsSup, Reason} = E, RaSystemsSup) ->
229+
?LOG_ERROR(
230+
?MODULE_STRING ": Ra system supervisor exited with reason ~tp~n",
231+
[Reason],
232+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
233+
exit(E);
234+
handle_info(_Info, State) -> {noreply, State}.
235+
236+
code_change(_OldVsn, State, _Extra) -> {ok, State}.

0 commit comments

Comments
 (0)