Repository navigation
Conversation
petermm
force-pushed
the
fix/jit-context-reuse
branch
from
October 30, 2026 13:29
b19ede8 to
c0c0380
Compare
pguyot
reviewed
Oct 31, 2026
petermm
force-pushed
the
fix/jit-context-reuse
branch
from
October 31, 2026 08:37
c0c0380 to
809153d
Compare
pguyot
reviewed
Oct 31, 2026
jit_terminate_context() destroyed the dispatched context and then returned the context scheduler_run() picked next. scheduler_entry_point compares that context with the one it dispatched to decide whether the same context keeps running, and the generated return_if_not_equal_to_ctx comparison checks the value a primitive returns the same way. A spawn on another scheduler thread can reuse the just freed address, so the comparison succeeds for the new process: the dispatcher keeps the terminated process's module and continuation and resumes the new process there, with the new process's empty stack and its own cp. It surfaces as a stack pop in an unrelated module, typically socket:accept0/2, followed by "Context heap is corrupted, cannot find fragment with stack pointer". Hand the next context to the dispatcher through JITState and return NULL from jit_terminate_context(), so neither comparison can mistake a recycled context for the dispatched one. test_net_kernel ran 500 times on macOS arm64 with the JIT with no crash, no hang and no failure, against roughly one failure per 60 to 300 runs before. The exact signature in the CI log was not reproduced locally, before or after the change; the wrong-continuation symptom was. Fixes: atomvm#2453 Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
petermm
force-pushed
the
fix/jit-context-reuse
branch
from
October 31, 2026 22:14
809153d to
1f2767a
Compare
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.
jit_terminate_context() destroyed the dispatched context and then returned the context scheduler_run() picked next. scheduler_entry_point compares that context with the one it dispatched to decide whether the same context keeps running, and the generated return_if_not_equal_to_ctx comparison checks the value a primitive returns the same way. A spawn on another scheduler thread can reuse the just freed address, so the comparison succeeds for the new process: the dispatcher keeps the terminated process's module and continuation and resumes the new process there, with the new process's empty stack and its own cp. It surfaces as a stack pop in an unrelated module, typically socket:accept0/2, followed by "Context heap is corrupted, cannot find fragment with stack pointer".
Hand the next context to the dispatcher through JITState and return NULL from jit_terminate_context(), so neither comparison can mistake a recycled context for the dispatched one.
test_net_kernel ran 500 times on macOS arm64 with the JIT with no crash, no hang and no failure, against roughly one failure per 60 to 300 runs before. The exact signature in the CI log was not reproduced locally, before or after the change; the wrong-continuation symptom was.
Fixes: #2453
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