Repository navigation
Don't need room on a dying process's heap to signal its links and monitors - #2501
gabrielmancini wants to merge 2 commits into
Conversation
…itors context_monitors_handle_terminate built the EXIT signal for a linked process, and the DOWN signal for a monitoring one, on the heap of the process that was terminating, and aborted the VM with "Cannot handle out of memory" when that heap could not take it, for example with a heap at its max_heap_size. mailbox_send_term_signal copies the term into the signal, so the tuple is only needed until then: build it on a stack heap. The exit reason is delivered as before. Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
petermm
left a comment
There was a problem hiding this comment.
Review: local EXIT and DOWN delivery at the process heap limit
Commit: 13356686dd6c, reviewed against its parent. Verdict: No merge blockers found. Keep the C change; tighten the regression test. The independent Oracle review reached the same conclusion on the C change and flagged the exit-reason assertion below.
The temporary heaps have room for the EXIT tuple and for the DOWN tuple plus either reference representation. mailbox_send_term_signal copies the entire term tree synchronously, while the temporary tuple and the dying process's reason are both still live. The change preserves the alias reference's owner and ticks and leaves test registration complete. See context.c:899–964, mailbox.c:257–299, and memory.c:423–455.
P2 · Require a structured exit reason to arrive intact
test_oom_exit_signal.erl:44–77 uses the same accepted reasons for both worker modes and every heap pressure level. For example, a notification that incorrectly reports out_of_memory instead of {data, Data} would still pass every exit_with_data iteration. The content check is useful, but only runs if the notification already has the right shape.
Require the exact nonempty payload at Cells = 1, where the tiny worker has ample room under the 256-word cap. Keep accepting OOM outcomes in the rest of the sweep, but accept boom only from fail. Both EXIT and DOWN use the same assertion.
--- a/tests/erlang_tests/test_oom_exit_signal.erl
+++ b/tests/erlang_tests/test_oom_exit_signal.erl
@@ -46,7 +46,7 @@
monitor, {max_heap_size, ?MAX_HEAP}
]),
receive
- {'DOWN', Ref, process, Pid, Reason} -> ok = expected(Cells, Reason)
+ {'DOWN', Ref, process, Pid, Reason} -> ok = expected(How, Cells, Reason)
end,
monitored(How, Cells + 1).
@@ -62,19 +62,21 @@
linked(How, Cells) ->
Pid = spawn_opt(?MODULE, worker, [{How, Cells}], [link, {max_heap_size, ?MAX_HEAP}]),
receive
- {'EXIT', Pid, Reason} -> ok = expected(Cells, Reason)
+ {'EXIT', Pid, Reason} -> ok = expected(How, Cells, Reason)
end,
linked(How, Cells + 1).
% The reason may live on the heap of the process that died: it must arrive
% whole. A worker may also run out of memory before it gets to exit.
-expected(Cells, {data, Data}) -> check_data(Data, Cells);
-expected(_Cells, {boom, _Stacktrace}) -> ok;
-expected(_Cells, boom) -> ok;
-expected(_Cells, out_of_memory) -> ok;
-expected(_Cells, {out_of_memory, _}) -> ok;
-expected(_Cells, killed) -> ok;
-expected(_Cells, Other) -> {unexpected, Other}.
+expected(exit_with_data, Cells, {data, Data}) -> check_data(Data, Cells);
+% This small worker has room to construct its reason; do not accept OOM here.
+expected(exit_with_data, 1, Other) -> {unexpected, Other};
+expected(fail, _Cells, {boom, _Stacktrace}) -> ok;
+expected(fail, _Cells, boom) -> ok;
+expected(_How, _Cells, out_of_memory) -> ok;
+expected(_How, _Cells, {out_of_memory, _}) -> ok;
+expected(_How, _Cells, killed) -> ok;
+expected(_How, _Cells, Other) -> {unexpected, Other}.
check_data(Data, Cells) ->
Data = fill(Cells, []),P3 · Fail promptly when a notification never matches
The two receives in test_oom_exit_signal.erl:48–66 have no deadline. A dropped notification or one with the wrong PID or reference would stall test-erlang until an external timeout, without identifying the failing iteration. Follow the existing monitor test's five-second deadline and report which signal and worker case failed. This snippet builds on the P2 diff.
--- a/tests/erlang_tests/test_oom_exit_signal.erl
+++ b/tests/erlang_tests/test_oom_exit_signal.erl
@@ -47,5 +47,7 @@
]),
receive
{'DOWN', Ref, process, Pid, Reason} -> ok = expected(How, Cells, Reason)
+ after 5000 ->
+ error({missing_down, How, Cells})
end,
monitored(How, Cells + 1).
@@ -63,5 +65,7 @@
Pid = spawn_opt(?MODULE, worker, [{How, Cells}], [link, {max_heap_size, ?MAX_HEAP}]),
receive
{'EXIT', Pid, Reason} -> ok = expected(How, Cells, Reason)
+ after 5000 ->
+ error({missing_exit, How, Cells})
end,
linked(How, Cells + 1).Out of scope: The mailbox still allocates signal storage from the system heap, and term sizing can allocate scratch space. System allocator failure remains unsafe; that predates this change. The fix is for exhaustion of the dying process's bounded VM heap, not for system-wide OOM.
Verification: Both diffs applied cleanly in order to a temporary copy of the committed test, and the amended test passed on OTP 29. The AtomVM runtime was reviewed from source, not built or tested for this review.
Accept each reason only from the worker mode that produces it, require the data to arrive in the smallest case, and fail after five seconds when a notification does not arrive. Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
|
Thanks! Applied both test changes: stricter exit reasons per worker mode, and a 5 s deadline on the receives. |
context_monitors_handle_terminatebuilds theEXITsignal for a linked process, and theDOWNsignal for a monitoring one, on the heap of the process that is terminating. When that heap cannot take the tuple, for example a heap at itsmax_heap_size, the VM aborts:mailbox_send_term_signalalready copies the term into the signal, so the tuple is only needed until then. With this change it is built on a stack heap (BEGIN_WITH_STACK_HEAP, as elsewhere incontext.c), and the exit reason is delivered as before.Field data: the serial logs of our ESP32 boards have this message at about 190 distinct times between 21 October and 26 November. In the VM our boards run today it is only printed at these two places. Older VMs logged most of them, and their sources were not checked.
Not covered: if the
mallocof the signal itself fails,mailbox_message_create_from_termreturnsNULLandmailbox_send_term_signalposts it, which dereferences it. That is shared by every term signal and is unchanged here.Tests:
test_oom_exit_signallets processes with a boundedmax_heap_sizedie with their heaps filled by 0 to 255 cells, monitored and linked, both by raising an error and by exiting with a reason that lives on their own heap, which must arrive whole.test-erlangsuite passes, and the new test also passes on BEAM withtest-erlang -b, with and without-s prime_smp. BEAM prints an error report for each worker it kills.Cannot handle out of memory.and callsabort(); with it, the test passes. The only failure in that run istest_socket, which also fails onrelease-0.7without this change.