[WIP] src: fix integration of Atomics.waitAsync() #44409
Draft
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.
Previously we unref the timers scheduled by
PostDelayedTask()
andPostNonNestableDelayedTask()
, which had been fine because theywere only ever scheduled by GC or logging so it didn't hurt to
stop the event loop early and ignore them. But now that
Atomics.waitAsync()
usesPostNonNestableDelayedTask()
toresolve a promise, we should keep the event loop open for it.
From offline discussion with @syg, what happens with a
Atomics.waitAsync()
with a timeout on an atomics that does not get notified in time is host-defined. For a host like Node.js, it makes sense to keep running until the returned promise resolves with atimed-out
value i.e. makes it similar to howsetTimeout()
would behave.This fix is not yet ready though, pending issues:
Atomics.waitAsync()
timeout is cancelled. From what I can tell, V8 only internally marks that task as cancelled, and when the platform runs the task throughtask->Run()
, V8'sRun()
implementation of that task sees that it's internally cancelled and skips it. Without knowing that the task is already canceled, the embedder would keep the isolate alive for longer than necessary.PostNonNestableDelayedTask()
supposed to be thread-safe for this use case (at least for the foreground task runner)? IIUC the V8 header does not specify thread safety for the TaskRunner methods, though the default V8 platform has been implemented with thread safety in mind. Currently this method of the foreground task runner is not thread-safe in Node.js because of the access to the main loop.Opened https://bugs.chromium.org/p/v8/issues/detail?id=13238 for the issues above