-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[application_controller] Stop starting applications when terminating …
…node Applications that didn't finish starting could be left in a half-broken state during node shutdown. In particular, their dependencies would be already shut down, while the application itself was running, likely with many errors. The behaviour is to replicate what happens if the application finished starting - with timeout set, we'll respect this timeout; otherwise we'll wait forever.
- Loading branch information
1 parent
48b3ad5
commit 7f0ee75
Showing
5 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{application, slow, [ | ||
{vsn, "1"}, | ||
{registered, []}, | ||
{applications, [kernel, stdlib]}, | ||
{modules, [slow]}, | ||
{mod, {slow, []}}, | ||
{env, []} | ||
]}. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-module(slow). | ||
-behaviour(application). | ||
-behaviour(supervisor). | ||
-behaviour(gen_server). | ||
-compile(export_all). | ||
|
||
|
||
%%%----------------------------------------------------------------- | ||
%%% application callbacks | ||
start(_StartType, _StartArgs) -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, supervisor). | ||
|
||
stop(_State) -> | ||
ok. | ||
|
||
init(supervisor) -> | ||
Child = #{id => main, start => {gen_server, start_link, [?MODULE, server, []]}}, | ||
{ok, {#{}, [Child]}}; | ||
init(server) -> | ||
{ok, Controller} = application:get_env(slow, controller), | ||
process_flag(trap_exit, true), | ||
Controller ! {server_starting, self()}, | ||
receive | ||
continue -> ok | ||
end, | ||
{ok, #{controller => Controller}}. | ||
|
||
terminate(_Reason, #{controller := Controller}) -> | ||
case application:get_env(slow, terminate) of | ||
{ok, Fun} -> Fun(); | ||
_ -> ok | ||
end, | ||
Controller ! server_terminating, | ||
ok. |