-
Notifications
You must be signed in to change notification settings - Fork 4k
Terminate when ra_systems_sup exits #15782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| -module(rabbit_ra_systems). | ||
|
|
||
| -behaviour(gen_server). | ||
|
|
||
| -include_lib("kernel/include/logger.hrl"). | ||
|
|
||
| -include_lib("rabbit_common/include/logging.hrl"). | ||
|
|
@@ -20,6 +22,21 @@ | |
| ensure_started/0, | ||
| ensure_stopped/0]). | ||
|
|
||
| -export([start_link/0, | ||
| init/1, | ||
| handle_call/3, | ||
| handle_cast/2, | ||
| handle_info/2, | ||
| terminate/2, | ||
| code_change/3]). | ||
| -export([stop/0]). | ||
|
|
||
| -rabbit_boot_step({rabbit_ra_systems_monitor, | ||
| [{description, "monitor process to shut down when Ra systems exit"}, | ||
| {mfa, {rabbit_sup, start_child, [?MODULE]}}, | ||
| {requires, [kernel_ready]}, | ||
| {cleanup, {?MODULE, stop, []}}]}). | ||
|
|
||
| -type ra_system_name() :: atom(). | ||
|
|
||
| -define(COORD_WAL_MAX_SIZE_B, 64_000_000). | ||
|
|
@@ -192,3 +209,38 @@ ensure_ra_system_stopped(RaSystem) -> | |
| #{domain => ?RMQLOG_DOMAIN_GLOBAL}), | ||
| throw(Error) | ||
| end. | ||
|
|
||
| %% ---------------------------------------------------------------------------- | ||
|
|
||
| start_link() -> | ||
| gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). | ||
|
|
||
| stop() -> | ||
| case supervisor:terminate_child(rabbit_sup, ?MODULE) of | ||
| ok -> ok = supervisor:delete_child(rabbit_sup, ?MODULE); | ||
| {error, not_found} -> ok | ||
| end. | ||
|
|
||
| init(_) -> | ||
| process_flag(trap_exit, true), | ||
| Pid = whereis(ra_systems_sup), | ||
| true = link(Pid), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t you need to unlink in the |
||
| {ok, Pid, hibernate}. | ||
|
|
||
| handle_call(_Request, _From, State) -> {noreply, State}. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will leave the caller waiting for a reply, until timeout if it set one. I think you can reply with an |
||
|
|
||
| handle_cast(_Msg, State) -> {noreply, State}. | ||
|
|
||
| handle_info({'EXIT', RaSystemsSup, Reason} = E, RaSystemsSup) -> | ||
| ?LOG_ERROR( | ||
| ?MODULE_STRING ": Ra system supervisor exited with reason ~tp~n", | ||
| [Reason], | ||
| #{domain => ?RMQLOG_DOMAIN_GLOBAL}), | ||
| exit(E); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about returning
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah actually, Rabbit doesn't exit unless we use |
||
| handle_info(_Info, State) -> {noreply, State}. | ||
|
|
||
| terminate(_, RaSystemsSup) -> | ||
| true = unlink(RaSystemsSup), | ||
| ok. | ||
|
|
||
| code_change(_OldVsn, State, _Extra) -> {ok, State}. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an extra gen_server just to crash the Rabbit app seems a bit hacky to me, though it works. I'm sure there must be a better way to crash Rabbit when ra_systems_sup exits.