diff options
author | José Valim <jose.valim@dashbit.co> | 2023-05-04 12:31:24 +0200 |
---|---|---|
committer | José Valim <jose.valim@dashbit.co> | 2023-05-04 12:31:27 +0200 |
commit | b0cbe265848a991f3777946386e1aace44aef7ef (patch) | |
tree | f13520ac836d5de76cafd31078413d8355b326e6 | |
parent | 14c55d15afbf08b0d8289a4399a15b4109b6ac5a (diff) | |
download | elixir-b0cbe265848a991f3777946386e1aace44aef7ef.tar.gz |
Avoid race between scripts and System.stop, closes #12524
-rw-r--r-- | lib/elixir/lib/system.ex | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/elixir/lib/system.ex b/lib/elixir/lib/system.ex index 3178e8565..09825c38f 100644 --- a/lib/elixir/lib/system.ex +++ b/lib/elixir/lib/system.ex @@ -452,7 +452,7 @@ defmodule System do The function must receive the exit status code as an argument. If the VM terminates programmatically, via `System.stop/1`, `System.halt/1`, - or exit signals, the `at_exit/1` callbacks are not executed. + or exit signals, the `at_exit/1` callbacks are not guaranteed to be executed. """ @spec at_exit((non_neg_integer -> any)) :: :ok def at_exit(fun) when is_function(fun, 1) do @@ -901,10 +901,12 @@ defmodule System do def stop(status \\ 0) def stop(status) when is_integer(status) do + at_exit(fn _ -> Process.sleep(:infinity) end) :init.stop(status) end def stop(status) when is_binary(status) do + at_exit(fn _ -> Process.sleep(:infinity) end) :init.stop(String.to_charlist(status)) end |