Repository navigation
fix: keep only what a plugin command's pipes hold at its exit - #6824
Merged
Merged
Conversation
Collaborator
Author
|
Review outcome for 494c97d.
|
At the leader's observed exit, one nonblocking read takes what each output pipe holds and the stream ends, so a process that escaped the group kill cannot append output while cleanup waits for the pipes to close. A read that fills its 1 MiB buffer falls back to the close-wait. Windows keeps the close-wait. Refs #6816.
janicduplessis
force-pushed
the
fix/6816-pipe-drain
branch
from
December 2, 2026 22:01
494c97d to
df9900e
Compare
Collaborator
Author
janicduplessis
marked this pull request as ready for review
December 2, 2026 22:02
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.
Description
When a
cleanupOnExitchild's leader exits,reportChildwaits up to 1 s for the child's pipes to close, then destroys them (#6818). A process that escaped the group kill (for example adetached: truehelper) and keeps the inherited stdout open gets anything it writes in that second appended to the result. A leader that writes{"ok":true}and leaves a helper that writeslateafterwards returns{"ok":true}lateonmain, which breaks callers that parse the whole output as JSON. The wait also costs the full second whenever such a process holds a pipe.Affected callers:
host.execin project plugins, andspawnManagedCapture().finish(), whose caller has already read the output by then.Solution
At the leader's observed exit, before the group kill, one nonblocking read takes whatever each output pipe holds, the handle stops reading, and the stream ends the way Node ends it on EOF (
onStreamRead). The stream then closes on its own, so the 1 s wait no longer hits its cap on POSIX.One read, not a loop until
EAGAIN: libuv gives child stdio as a Unix stream socketpair with 64 KiB socket buffers, and one read of a stream socket returns what is queued up to the buffer size (1 MiB). A loop would let a detached writer that was blocked on the full pipe refill it after each read. A read that fills the whole 1 MiB may have left output behind (a leader can raise its ownSO_SNDBUF), so that stream keeps reading and falls back to the 1 s close-wait, as onmain.Risk: this reads Node's undocumented
child.stdout._handle.fdand callsreadStop()on the handle. No public API reads a child pipe without waiting for EOF. The issue's other ideas are worse: droppingcleanupOnExitforhost.execwould wait for a held pipe until the call's timeout and append even more, and file-backed stdio would still need a size snapshot at the exit.Limits, also named at the call site:
exitevent are kept. A helper that writes the instant its pipe from the leader closes lands in the output every time (10 of 10 in a local probe). Nothing sharing the pipe can tell those bytes apart, so Leader-exit pipe drain can still truncate or append output in edge cases #6816 stays open for this case.main's behavior.The drain runs before
cancelstores its promise, so an overflow cancel triggered by the drained bytes takes over cleanup instead of starting a second one.The issue's truncation case was already fixed by #6818; the split-output row below keeps it covered under the new mechanism.
Test plan
exec.integration.test.ts, on macOS with Node 22.22.2 and 24.22.1:late. Fails onmainwith{"ok":true}late, passes here.mainthe output grows past 1 MiB; here it stays under. This row fails onmainevery time; it caught a loop-until-EAGAINdrain only in some runs, since that depends on the writer winning the race.SO_SNDBUFto 4 MiB and writes 3 MiB plus a marker. Passes onmain, fails with a single read and no fallback, passes here.maintoo, and fails here if the drained bytes are not pushed into the stream.The detached rows are skipped on Windows. PR CI does not run integration tests, so they also ran on Linux through a dispatched
CIrun on this branch. Thehost.exec,runCapturedand report-listing suites pass (plugin-command,plugin-output-members,plugin-ios-module,kit-project-worker,engine-deps,report-listing,api-reports), and the full local unit suite passes.Refs #6816