Fix main-loop immediate fallback isolation and cleanup - #27707
Draft
patrickcorrigan wants to merge 2 commits into
Draft
patrickcorrigan wants to merge 2 commits into
patrickcorrigan wants to merge 2 commits into
Conversation
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.
EM_TIMING_SETIMMEDIATE's message fallback registers a global listener per module, but every listener recognizes the samesetimmediatestring. Exiting an instance leaves its listener installed. A later instance's message can therefore callsetImmediates.shift()()on the exited instance's empty queue, throwingTypeError: setImmediates.shift(...) is not a function. The listener also retains the old module and its linear-memory buffer. Sequential module creation is sufficient to reproduce this; overlapping active instances are not required.Use a private
MessageChannelfor each module's fallback, including when running in a Worker. Clear queued callbacks, detach the handler and close both ports on runtime exit and before invokingonAbort. Make disposal idempotent and prevent an unwinding runner from recreating the channel or scheduling more work. The nativescheduler.postTaskand NodesetImmediatepaths remain in place. This changes the main-loop timing fallback, not the separateemscripten_set_immediateAPI.The regression exercises two separately evaluated modularized factories, repeated and concurrent instances, pause/resume, timing changes, cancel/restart, normal exit, forced exit, and abort, including an
onAbortcallback that throws. Abort coverage also runs withoutEXIT_RUNTIME. It checks remaining listeners/ports and unexpected errors. The existing polyfill test now actually hidesscheduler, and also runs throughPROXY_TO_PTHREAD.Validation
Against upstream
e34b2b50a1ffd755a4b746b85dbeeab6b255195e, using the exact SDK revision intest/emsdk_version.txt(83b1bdcbbb44ea970025bc08a5fb3c696c78e037) and Chromium 153.0.8010.36:Actual Safari/iOS and full-suite validation remain outstanding. Minimal runtime has different shutdown semantics; a main-loop experiment on unchanged upstream also encountered an existing
ABORT is not definederror. This PR does not claim to fix minimal-runtime lifecycle support.Related reports and discussion
window.addEventListenerleak. This PR addresses that main-loop fallback; it does not claim to fix the already-addressed pthread mailbox issue itself.MODULARIZEfor independently compiled programs sharing a page. This is related usage context, not an earlier report of this exact defect.scheduler.postTaskpath; the fallback still needs independent ownership and cleanup.