Skip to content

fix(agent): bound Wait on abandoned stdout/stderr pipes (session leak)#5

Merged
CMGS merged 1 commit into
mainfrom
fix/exec-waitdelay-leak
Jul 3, 2026
Merged

fix(agent): bound Wait on abandoned stdout/stderr pipes (session leak)#5
CMGS merged 1 commit into
mainfrom
fix/exec-waitdelay-leak

Conversation

@CMGS

@CMGS CMGS commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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.Wait blocks 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-side cocoon vm exec hangs 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)
  • ErrWaitDelay mapped to the command's real exit code from ProcessState — MsgExit semantics unchanged
  • Cancel-path pgkill semantics untouched: deliberate daemons survive a normal session end (kubectl-exec-like), protocol errors / disconnects still kill the whole pgroup

Verification

  • New regression test TestServerExecBackgroundChildDoesNotPinSession (sh -c 'sleep 6 & echo started'): without fix FAIL 6.29s (pinned), with fix PASS 2.01s (= WaitDelay signature) — negative-tested both ways
  • make lint 0 issues × {linux, darwin, windows}; full test suite green (agent 83.6%, client 21.2%)

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.
@CMGS CMGS merged commit 12488df into main Jul 3, 2026
2 checks passed
@CMGS CMGS deleted the fix/exec-waitdelay-leak branch July 3, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant