lib: keep event loop alive for pending Atomics.waitAsync#61982
Open
igor-shevelenkov wants to merge 1 commit intonodejs:mainfrom
Open
lib: keep event loop alive for pending Atomics.waitAsync#61982igor-shevelenkov wants to merge 1 commit intonodejs:mainfrom
igor-shevelenkov wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Renegade334
requested changes
Feb 25, 2026
Member
Renegade334
left a comment
There was a problem hiding this comment.
Replacing global-scope ES builtins with proxies is a big no-no. Resolving the issues in #44409 will be the correct way forward.
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.
Summary
Fixes #61941.
Pending
Atomics.waitAsync()operations now keep the Node.js event loop alive until they settle, so the process does not exit early when the wait is the only pending async operation.Problem
Atomics.waitAsync()returns a promise-like result, but that pending wait did not ref the event loop.If nothing else was ref'd, Node could terminate before
Atomics.notify()(or timeout) resolved the wait.This affects real-world patterns like multithreaded WASM / Emscripten where completion is signaled via atomics from non-libuv worker activity.
Approach
Introduced
internal/atomics/wait_asyncwithtrackWaitAsyncResult(result):result.async === false) untouched.Integrated this in two places:
lib/internal/bootstrap/node.jsWrap
globalThis.Atomics.waitAsyncso userland calls are tracked.lib/internal/worker/messaging.jsWrap internal primordial
AtomicsWaitAsyncusage sopostMessageToThread()also keeps the loop alive while awaiting the shared-status wait.Tests
Added regression coverage:
test/parallel/test-atomics-waitasync-event-loop.mjsnot-equalpathtest/parallel/test-worker-messaging-event-loop-ref.mjspostMessageToThread()internal wait path does not allow early process exitNotes
This is a Node-side lifecycle fix around the V8-provided waitAsync result, preserving existing API behavior while correcting event-loop liveness semantics.