File 1252-Do-not-unload-modules-during-stop.patch of Package erlang
From 60c744567b1b56360ab02113aeb853b767e11746 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@dashbit.co>
Date: Wed, 7 Jul 2021 17:03:09 +0200
Subject: [PATCH] Do not unload modules during stop
Closes #5031.
---
erts/preloaded/src/init.erl | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl
index 3cf837791a..5b59a9d65f 100644
--- a/erts/preloaded/src/init.erl
+++ b/erts/preloaded/src/init.erl
@@ -423,7 +423,7 @@ new_kernelpid({_Name,ignore},BootPid,State) ->
State;
new_kernelpid({Name,What},BootPid,State) ->
erlang:display({"could not start kernel pid",Name,What}),
- clear_system(BootPid,State),
+ clear_system(false,BootPid,State),
crash("could not start kernel pid", [Name, What]).
%% Here is the main loop after the system has booted.
@@ -531,7 +531,7 @@ set_flag(_,_,_) ->
%%% -------------------------------------------------
%%% Stop the system.
-%%% Reason is: restart | reboot | stop
+%%% Reason is: restart | {restart, Mode} | reboot | stop
%%% According to reason terminate emulator or restart
%%% system using the same init process again.
%%% -------------------------------------------------
@@ -540,7 +540,8 @@ stop(Reason,State) ->
BootPid = State#state.bootpid,
{_,Progress} = State#state.status,
State1 = State#state{status = {stopping, Progress}},
- clear_system(BootPid,State1),
+ %% There is no need to unload code if the system is shutting down
+ clear_system(Reason=/=stop,BootPid,State1),
do_stop(Reason,State1).
do_stop(restart,#state{start = Start, flags = Flags, args = Args}) ->
@@ -556,10 +557,10 @@ do_restart(Start,Flags,Args) ->
stop_heart(State),
halt(Status).
-clear_system(BootPid,State) ->
+clear_system(Unload,BootPid,State) ->
Heart = get_heart(State#state.kernel),
shutdown_pids(Heart,BootPid,State),
- unload(Heart).
+ Unload andalso unload(Heart).
flush() ->
receive
--
2.31.1