From 4a31b4055717b5bbbfbc01ed72ac372dc662630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:17:25 +0100 Subject: [PATCH 1/7] Use :erlang.exit_signal/2 in Process.exit/2 :erlang.exit/2 is deprecated in upcoming Erlang/OTP versions. exit_signal/2 has been available since Erlang/OTP 21 and differs only when the calling process signals itself: :normal no longer terminates it and other reasons are delivered asynchronously. Assisted-by: Claude Code:claude-opus-5-5 --- CHANGELOG.md | 1 + lib/elixir/lib/kernel/cli.ex | 2 +- lib/elixir/lib/process.ex | 10 +++++----- lib/elixir/src/elixir_rewrite.erl | 2 +- lib/elixir/test/elixir/process_test.exs | 15 ++++++++++----- lib/ex_unit/lib/ex_unit/assertions.ex | 2 +- lib/ex_unit/test/ex_unit/callbacks_test.exs | 6 +++++- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca636264773..f100c87c8fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * [List] Add `List.to_existing_atom/2` and `List.to_unsafe_atom/1` * [MapSet] Optimize `MapSet.symmetric_difference/2` when set sizes differ * [Path] Add `Path.safe_join/2` + * [Process] `Process.exit/2` now uses `:erlang.exit_signal/2`, as `:erlang.exit/2` is deprecated in upcoming Erlang/OTP versions. Therefore `Process.exit(self(), :normal)` no longer terminates the calling process and `Process.exit(self(), reason)` delivers the signal asynchronously. Use `exit/1` to terminate the calling process * [Protocol] Add the `:skip_consolidated` option to `Protocol.extract_protocols/2` * [Protocol] Warn when implementing a protocol for a module that does not define a struct * [Registry] Add the `:spawn_opt` option to `Registry.start_link/1` diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index f1a67e14e6b..5f1ea27664f 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -450,7 +450,7 @@ defmodule Kernel.CLI do end :exit, {kind, exit} when kind in [:exception, :signal] -> - Process.exit(self(), exit) + exit(exit) else :ok -> :ok {kind, reason, stack} -> :erlang.raise(kind, reason, stack) diff --git a/lib/elixir/lib/process.ex b/lib/elixir/lib/process.ex index ac6b158f636..2edc3d54f0e 100644 --- a/lib/elixir/lib/process.ex +++ b/lib/elixir/lib/process.ex @@ -205,10 +205,10 @@ defmodule Process do Exit behavior differs based on the value of `reason`: - - If `:normal`, `pid` will not exit unless it is the calling process, in - which case it will exit with the reason `:normal`. If it is trapping exits, - the exit signal is transformed into a message `{:EXIT, from, :normal}` and - delivered to its message queue. + - If `:normal`, `pid` will not exit. If it is trapping exits, the exit + signal is transformed into a message `{:EXIT, from, :normal}` and + delivered to its message queue. This also applies when `pid` is the + calling process. - If `:kill`, which occurs when `Process.exit(pid, :kill)` is called, an untrappable exit signal is sent to `pid` which will unconditionally exit @@ -240,7 +240,7 @@ defmodule Process do """ @spec exit(pid, term) :: true - defdelegate exit(pid, reason), to: :erlang + defdelegate exit(pid, reason), to: :erlang, as: :exit_signal @doc """ Sleeps the current process for the given `timeout`. diff --git a/lib/elixir/src/elixir_rewrite.erl b/lib/elixir/src/elixir_rewrite.erl index bfa2f3154cb..23e2d2dd9b3 100644 --- a/lib/elixir/src/elixir_rewrite.erl +++ b/lib/elixir/src/elixir_rewrite.erl @@ -189,7 +189,7 @@ inner_inline(ex_to_erl, ?list, to_atom, 1) -> {erlang, list_to_atom}; ?inline(?process, cancel_timer, 2, erlang, cancel_timer); ?inline(?process, demonitor, 1, erlang, demonitor); ?inline(?process, demonitor, 2, erlang, demonitor); -?inline(?process, exit, 2, erlang, exit); +?inline(?process, exit, 2, erlang, exit_signal); ?inline(?process, flag, 2, erlang, process_flag); ?inline(?process, flag, 3, erlang, process_flag); ?inline(?process, get, 0, erlang, get); diff --git a/lib/elixir/test/elixir/process_test.exs b/lib/elixir/test/elixir/process_test.exs index db60db627f0..7e52ea190f8 100644 --- a/lib/elixir/test/elixir/process_test.exs +++ b/lib/elixir/test/elixir/process_test.exs @@ -139,11 +139,16 @@ defmodule ProcessTest do refute Process.alive?(pid) end - test "exit(self(), :normal) causes the calling process to exit" do - Process.flag(:trap_exit, true) - pid = spawn_link(fn -> Process.exit(self(), :normal) end) - assert_receive {:EXIT, ^pid, :normal} - refute Process.alive?(pid) + test "exit(self(), :normal) does not cause the calling process to exit" do + parent = self() + + pid = + spawn(fn -> + Process.exit(self(), :normal) + send(parent, {self(), :alive}) + end) + + assert_receive {^pid, :alive} end describe "alias/0, alias/1, and unalias/1" do diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index 45add356a88..ed53d715814 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -952,7 +952,7 @@ defmodule ExUnit.Assertions do with `Process.flag/2` and assert the exit message with `assert_receive/2`. Process.flag(:trap_exit, true) - pid = spawn_link(fn -> Process.exit(self(), :normal) end) + pid = spawn_link(fn -> exit(:normal) end) assert_receive {:EXIT, ^pid, :normal} """ diff --git a/lib/ex_unit/test/ex_unit/callbacks_test.exs b/lib/ex_unit/test/ex_unit/callbacks_test.exs index 6b3b37eaa8b..a3939be30a8 100644 --- a/lib/ex_unit/test/ex_unit/callbacks_test.exs +++ b/lib/ex_unit/test/ex_unit/callbacks_test.exs @@ -183,7 +183,11 @@ defmodule ExUnit.CallbacksTest do use ExUnit.Case, async: false test "ok" do - on_exit(fn -> Process.exit(self(), :kill) end) + on_exit(fn -> + Process.exit(self(), :kill) + Process.sleep(:infinity) + end) + :ok end end From fe59ca23eb0525da9de1733acdc1aa3f04bf4f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:19:35 +0100 Subject: [PATCH 2/7] Do not update CHANGELOG Assisted-by: Claude Code:claude-opus-5-5 --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f100c87c8fa..ca636264773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,6 @@ * [List] Add `List.to_existing_atom/2` and `List.to_unsafe_atom/1` * [MapSet] Optimize `MapSet.symmetric_difference/2` when set sizes differ * [Path] Add `Path.safe_join/2` - * [Process] `Process.exit/2` now uses `:erlang.exit_signal/2`, as `:erlang.exit/2` is deprecated in upcoming Erlang/OTP versions. Therefore `Process.exit(self(), :normal)` no longer terminates the calling process and `Process.exit(self(), reason)` delivers the signal asynchronously. Use `exit/1` to terminate the calling process * [Protocol] Add the `:skip_consolidated` option to `Protocol.extract_protocols/2` * [Protocol] Warn when implementing a protocol for a module that does not define a struct * [Registry] Add the `:spawn_opt` option to `Registry.start_link/1` From e608137f15ef537c95a1c1980e15509de9e65334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:20:57 +0100 Subject: [PATCH 3/7] Report remote exit signals as --rpc-eval failures Assisted-by: Claude Code:claude-opus-5-5 --- lib/elixir/lib/kernel/cli.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index 5f1ea27664f..d76492f21e3 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -449,8 +449,8 @@ defmodule Kernel.CLI do {:error, "--rpc-eval : RPC failed with reason #{inspect(reason)}"} end - :exit, {kind, exit} when kind in [:exception, :signal] -> - exit(exit) + :exit, {kind, reason} when kind in [:exception, :signal] -> + {:error, "--rpc-eval : RPC failed with reason #{inspect(reason)}"} else :ok -> :ok {kind, reason, stack} -> :erlang.raise(kind, reason, stack) From 1d6cfed35bf5e4cbfdc6374eb6740d411e230dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:25:26 +0100 Subject: [PATCH 4/7] Preserve --rpc-eval output and halting on remote exit signals Assisted-by: Claude Code:claude-opus-5-5 --- lib/elixir/lib/kernel/cli.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index d76492f21e3..8f6300db8f4 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -450,7 +450,8 @@ defmodule Kernel.CLI do end :exit, {kind, reason} when kind in [:exception, :signal] -> - {:error, "--rpc-eval : RPC failed with reason #{inspect(reason)}"} + print_error({:EXIT, self()}, reason, []) + exit({:shutdown, 1}) else :ok -> :ok {kind, reason, stack} -> :erlang.raise(kind, reason, stack) From b68b32f158a0d8a99c4dac06fadf7ff2141363c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:26:47 +0100 Subject: [PATCH 5/7] Wait for the exit signal in --rpc-eval Assisted-by: Claude Code:claude-opus-5-5 --- lib/elixir/lib/kernel/cli.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index 8f6300db8f4..08e18c462eb 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -449,9 +449,9 @@ defmodule Kernel.CLI do {:error, "--rpc-eval : RPC failed with reason #{inspect(reason)}"} end - :exit, {kind, reason} when kind in [:exception, :signal] -> - print_error({:EXIT, self()}, reason, []) - exit({:shutdown, 1}) + :exit, {kind, exit} when kind in [:exception, :signal] -> + Process.exit(self(), exit) + Process.sleep(:infinity) else :ok -> :ok {kind, reason, stack} -> :erlang.raise(kind, reason, stack) From 3c82d8a5ac194742db94fb48bfcb2cc0a0d9d64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:29:22 +0100 Subject: [PATCH 6/7] Document Process.exit/2 signals are always async Assisted-by: Claude Code:claude-opus-5-5 --- lib/elixir/lib/process.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/elixir/lib/process.ex b/lib/elixir/lib/process.ex index 2edc3d54f0e..38452e578d8 100644 --- a/lib/elixir/lib/process.ex +++ b/lib/elixir/lib/process.ex @@ -221,6 +221,13 @@ defmodule Process do transformed into a message `{:EXIT, from, reason}` and delivered to its message queue. + The exit signal is always sent asynchronously, even when `pid` is the + calling process. This means `Process.exit(self(), reason)` returns and + the calling process may continue executing before the signal is handled. + Prior to Elixir v1.21, if the calling process was not trapping exits, + it would exit before this function returned, including when `reason` + was `:normal`. Use `Kernel.exit/1` to stop the current process. + Inlined by the compiler. > #### Differences to `Kernel.exit/1` {: .info } From d1e4b98ca7b89905ac4f75062ec06823845d8999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 27 Oct 2026 12:29:39 +0100 Subject: [PATCH 7/7] Clarify previous Process.exit/2 self-signal behaviour Assisted-by: Claude Code:claude-opus-5-5 --- lib/elixir/lib/process.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/process.ex b/lib/elixir/lib/process.ex index 38452e578d8..4242aab6807 100644 --- a/lib/elixir/lib/process.ex +++ b/lib/elixir/lib/process.ex @@ -224,9 +224,9 @@ defmodule Process do The exit signal is always sent asynchronously, even when `pid` is the calling process. This means `Process.exit(self(), reason)` returns and the calling process may continue executing before the signal is handled. - Prior to Elixir v1.21, if the calling process was not trapping exits, - it would exit before this function returned, including when `reason` - was `:normal`. Use `Kernel.exit/1` to stop the current process. + Prior to Elixir v1.21, the calling process would exit before this function + returned whenever the signal terminated it, and `:normal` would terminate + it when not trapping exits. Use `Kernel.exit/1` to stop the current process. Inlined by the compiler.