Repository navigation
child_process: deliver each stdio event after the nextTicks and promise jobs of the one before #43790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
robobun
wants to merge
8
commits into
main
Choose a base branch
from
robobun/b94aed8d/child-stdio-end-after-data-jobs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+580
−28
Draft
child_process: deliver each stdio event after the nextTicks and promise jobs of the one before #43790
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eed6476
node:child_process: deliver each stdio event after the ticks and prom…
robobun 66871ac
child_process: queue a stdio stream's 'close' before the destroy call…
robobun 7b9dfc1
Shorten the comments of the after-tick-drain change to one line each
robobun 82080bf
Use the shared FIFO for the after-tick-drain queue
robobun 5b45752
Merge branch 'main' into robobun/b94aed8d/child-stdio-end-after-data-…
robobun 451e832
child_process: stdio 'close' carries hadError, and tests for a consum…
robobun 421f791
test: say that the held-open rows are not checked on Windows
robobun 1bbaee0
test: keep the grandchild of the held-open rows alive under BUN_FEATU…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Node empties the nextTick queue and the promise job queue between two libuv callbacks: https://github.com/nodejs/node/blob/v24.9.0/lib/internal/process/task_queues.js#L72-L109 | ||
| const asyncHooksTick = require("internal/async_hooks_tick"); | ||
|
|
||
| type AfterTickDrainCallback = { | ||
| callback: (arg: any) => void; | ||
| arg: unknown; | ||
| frame: import("../../node/async_hooks").Frame | undefined; | ||
| }; | ||
|
|
||
| // A queue: entries before `head` are done. Bounded by the number of callers, which each wait for their turn. | ||
| const entries: (AfterTickDrainCallback | undefined)[] = []; | ||
| let head = 0; | ||
|
|
||
| // Runs `callback` once both queues are empty, inside the drain that is running. One callback for each such point. | ||
| function runAfterTickDrain(callback: (arg: any) => void, arg?: unknown) { | ||
| let ensureTickLoop = asyncHooksTick.ensureTickLoop; | ||
| if (ensureTickLoop === undefined) { | ||
| // The first read of process.nextTick creates the tick queue. Fake timers read it before they replace it. | ||
| void process.nextTick; | ||
| ensureTickLoop = asyncHooksTick.ensureTickLoop; | ||
| // process.nextTick was overwritten before its first read: there is no tick loop to wait for. | ||
| if (ensureTickLoop === undefined) return process.nextTick(callback, arg); | ||
| } | ||
| ensureTickLoop(); | ||
| $arrayPush(entries, { callback, arg, frame: $getInternalField($asyncContext, 0) }); | ||
| } | ||
|
|
||
| // The tick loop calls this each time both queues are empty. False: nothing waited. | ||
| function runAfterTickDrainCallback() { | ||
| if (head === entries.length) return false; | ||
| const { callback, arg, frame } = entries[head]!; | ||
| entries[head++] = undefined; | ||
| if (head === entries.length) { | ||
| entries.length = 0; | ||
| head = 0; | ||
| } | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| const restore = $getInternalField($asyncContext, 0); | ||
| $putInternalField($asyncContext, 0, frame); | ||
| // No catch and no finally, as for a tick: JSNextTickQueue::drain reports the throw and calls the tick loop again. | ||
| callback(arg); | ||
| $putInternalField($asyncContext, 0, restore); | ||
| return true; | ||
| } | ||
| asyncHooksTick.runAfterTickDrainCallback = runAfterTickDrainCallback; | ||
|
|
||
| export default { runAfterTickDrain }; | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.