From b0cbe265848a991f3777946386e1aace44aef7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 4 May 2023 12:31:24 +0200 Subject: Avoid race between scripts and System.stop, closes #12524 --- lib/elixir/lib/system.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1