Repository navigation
Keep pending signals in order when dumping a crashed process - #2426
Merged
bettio merged 1 commit intoOct 14, 2026
Merged
Conversation
bettio
requested changes
Oct 13, 2026
bettio
left a comment
Collaborator
There was a problem hiding this comment.
I think it can be merged, I just added a couple of nitpick comments. If you don't mind git rebase it on latest release-0.7 branch.
Author
|
Thanks for the review! Rebased on latest
|
r3wretrhy
force-pushed
the
fix/crashdump-keep-outer-signals-2415
branch
from
October 13, 2026 09:50
585829e to
99903e2
Compare
bettio
requested changes
Oct 13, 2026
mailbox_crashdump moved the normal messages of the outer list to the inner list and then stored the remaining signals back with a plain assignment to outer_first. Two things went wrong with that: - a signal enqueued by another scheduler between the detach and the store was overwritten and lost. With a process monitored twice by a process that is killed while the monitored one crashes, one of the two DemonitorSignals could be lost this way, and context_destroy then aborted in context_monitors_handle_terminate on `assert(target != NULL)`; - the signals were stored back oldest first while the outer list is newest first, so context_destroy processed them in reverse order. Store the signals back newest first with a compare and exchange, chaining anything enqueued in the meantime in front of them. Fixes: atomvm#2415 Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
r3wretrhy
force-pushed
the
fix/crashdump-keep-outer-signals-2415
branch
from
October 13, 2026 14:15
99903e2 to
720cf33
Compare
|
Tested against the repro in #2415 (generic_unix, default build type so the assert is on, Linux x86_64):
Thanks for tracking it down. |
bettio
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The abort in #2415 comes from
mailbox_crashdump, not from the monitor code. When a process crashes, the crash report moves the normal messages from the outer list to the inner list so they can be printed, and then puts the signals back with a plain store:Another scheduler can enqueue a signal between the detach and that store. The store overwrites it. In the repro, A monitors B twice and is killed while B crashes. A's
context_destroysends B twoDemonitorSignals. If the second one arrives while B is printing its crash report, it is lost. B'scontext_destroythen still has aCONTEXT_MONITOR_MONITORED_LOCALentry for A, which is already gone, so it hitsassert(target != NULL). I traced this on the repro: A sent both demonitors, and B's destroy only received the first one. If B exitsnormal, there is no crash report and the repro never aborts.The same line also puts the signals back oldest first, but the outer list is newest first, so
context_destroyhandles signals that arrived before the crash in reverse order. The comment ("now in reverse order but the process crashed anyway") assumed this didn't matter. It does matter, because those signals are still processed afterwards.The signals now go back newest first with a compare and exchange. Anything enqueued in the meantime is detached and chained in front of them, because it is more recent. Only the owner detaches the outer list, so this can't race with another reader. Without SMP or the task driver, the store stays a plain assignment.
Testing (generic_unix, Debian 13, gcc, SMP):
test_mailbox_crashdump_keeps_signalsintest-mailbox: it sends signals before and after a crash dump and checks that they come out in received order. It fails onrelease-0.7and passes with this change. This test covers the ordering. The lost-signal race can't be reproduced deterministically in a unit test.monitor_race2from the issue (20000 iterations): 9/10 runs abort onrelease-0.7(1f37255). With this change, 30/30 runs returnok.test-erlangandtest-structspass, andtest-mailboxalso passes with-DAVM_DISABLE_SMP=ON.test_estdlibpassed until thegen_tcpconnect tests, which can't reach external hosts in my sandbox.I based this on
release-0.7like the other fixes. Note that #2423 also adds a test totest-mailbox.cmain(), so whichever lands second gets a trivial conflict there.Fixes #2415
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later