fix(agent): bound Wait on abandoned stdout/stderr pipes (session leak)#5
Merged
Conversation
A daemonizing exec (sh -c 'task &') leaves the background child holding the session's stdout/stderr pipe write-ends; cmd.Wait blocks until that child dies, pinning the handler goroutine, the vsock conn, and the pipe fds indefinitely. WaitDelay force-closes the pipes 2s after the command itself exits; ErrWaitDelay is mapped to the child's real exit code.
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.
The leak
vm exec -- sh -c 'task &': the shell exits instantly, but the daemonized child inherits the session's stdout/stderr pipe write-ends.cmd.Waitblocks until pipe EOF — i.e. until the background child dies, which for a real daemon is never. Each such exec pins: the handler goroutine, the vsock conn, the internal pipe fds, and the host-sidecocoon vm exechangs with it.Same family as the stdin-reader hang fixed in 7f796c5 (session join blocked), other side of the plumbing: stdout/stderr drain instead of stdin decode.
Fix
cmd.WaitDelay = 2s— after the command itself exits, abandoned pipes are force-closed and Wait returns (exec.ErrWaitDelay)ErrWaitDelaymapped to the command's real exit code fromProcessState— MsgExit semantics unchangedVerification
TestServerExecBackgroundChildDoesNotPinSession(sh -c 'sleep 6 & echo started'): without fix FAIL 6.29s (pinned), with fix PASS 2.01s (= WaitDelay signature) — negative-tested both waysmake lint0 issues × {linux, darwin, windows}; full test suite green (agent 83.6%, client 21.2%)