File 1011-Fix-suspend_process-issue-on-processes-in-dirty-sche.patch of Package erlang
From 6b80c626f0c90c55b949055f46ec4faacc8e4456 Mon Sep 17 00:00:00 2001
From: Daniel Gorin <danielgo@meta.com>
Date: Wed, 24 Sep 2025 19:42:44 +0100
Subject: [PATCH 1/3] Fix suspend_process() issue on processes in dirty
schedulers
# Context
`erlang:suspend_process()` was broken when applied on processes that
happened to be in a dirty-scheduler. The symptom was:
- `internal_error` would be returned when called synchronously
- `not_suspended` would be delivered when called asynchronously,
even though the process was in fact suspended
# Problem
When trying to suspend a processes in a dirty-scheduler, it is actually
the dirty-scheduler who suspends the process, by calling
`erts_proc_sig_handle_pending_suspend()`. This essentially activates all
pending suspend monitors and finally sends all pending sync messages, by
calling `sync_suspend_reply()`.
The problem is that when calling the latter, it is passing the process
state *before* activating the monitors. In particular, the SUSPENDED
flag is not set, what makes `sync_suspend_reply()` assume that something
is wrong.
---
erts/emulator/beam/erl_proc_sig_queue.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/erts/emulator/beam/erl_proc_sig_queue.c b/erts/emulator/beam/erl_proc_sig_queue.c
index ed10033772..74bbb0558c 100644
--- a/erts/emulator/beam/erl_proc_sig_queue.c
+++ b/erts/emulator/beam/erl_proc_sig_queue.c
@@ -5269,6 +5269,8 @@ erts_proc_sig_handle_pending_suspend(Process *c_p)
msp = next_msp;
}
+ state = erts_atomic32_read_nob(&c_p->state);
+
sync = psusp->sync;
while (sync) {
--
2.51.0