Skip to content

fix(core): stop capture hanging on orphaned pipes - #2322

Closed
fengjikui wants to merge 1 commit into
rtk-ai:developfrom
fengjikui:fix/dotnet-capture-orphan-pipes
Closed

fengjikui wants to merge 1 commit into
rtk-ai:developfrom
fengjikui:fix/dotnet-capture-orphan-pipes

Conversation

@fengjikui

Copy link
Copy Markdown
Contributor

Fixes #2320

Summary

  • replace Command::output() in exec_capture with explicit spawn/wait plus background stdout/stderr readers
  • return after the direct child exits once captured output is idle, with a bounded post-exit drain
  • add a regression test for a child that exits while a background descendant still holds the captured pipes open

Why

Some rtk dotnet ... commands can start helper descendants such as credential providers or MSBuild nodes. If those descendants inherit captured stdout/stderr, Command::output() waits for pipe EOF even after the direct dotnet child has exited, so RTK can appear to hang indefinitely. Waiting on the direct child separately avoids that EOF dependency while still preserving captured output from the command.

Validation

  • cargo fmt --check
  • cargo test core::stream::tests::test_exec_capture_returns_after_child_exits_when_grandchild_holds_pipe -- --nocapture
  • cargo test core::stream::tests::test_exec_capture -- --nocapture
  • cargo test core::stream -- --nocapture
  • cargo clippy --all-targets -- -D warnings
  • cargo test
  • git diff --check

pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 23, 2026
…an't hang capture

run_streaming's CaptureOnly path read child pipes to EOF. When the direct child
exits but leaves a descendant holding the captured stdout/stderr open (e.g.
'ng build' leaves an esbuild --service grandchild on node's stderr; dotnet leaves
MSBuild/NuGet daemons — issue rtk-ai#2320), the pipe never EOFs and rtk hangs forever.

Spawn background reader threads that drain each pipe into a shared buffer, wait on
the DIRECT child, then bound the post-exit drain: stop when both readers signal EOF,
when output stops growing for STREAM_POST_EXIT_IDLE_GRACE (200ms), or at the hard
STREAM_POST_EXIT_MAX_DRAIN (2s) cap. A reader still blocked on a grandchild-held
pipe is detached via try_join_finished instead of joined.

Same root cause as upstream rtk-ai#2322, which fixes exec_capture; this ports the
child-exit + bounded-drain pattern to run_streaming, the path rtk-ai#2322 leaves
untouched. +3 regression tests (return in <1s; would hang without the fix).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 25, 2026
…an't hang capture

run_streaming's CaptureOnly path read child pipes to EOF. When the direct child
exits but leaves a descendant holding the captured stdout/stderr open (e.g.
'ng build' leaves an esbuild --service grandchild on node's stderr; dotnet leaves
MSBuild/NuGet daemons — issue rtk-ai#2320), the pipe never EOFs and rtk hangs forever.

Spawn background reader threads that drain each pipe into a shared buffer, wait on
the DIRECT child, then bound the post-exit drain: stop when both readers signal EOF,
when output stops growing for STREAM_POST_EXIT_IDLE_GRACE (200ms), or at the hard
STREAM_POST_EXIT_MAX_DRAIN (2s) cap. A reader still blocked on a grandchild-held
pipe is detached via try_join_finished instead of joined.

Same root cause as upstream rtk-ai#2322, which fixes exec_capture; this ports the
child-exit + bounded-drain pattern to run_streaming, the path rtk-ai#2322 leaves
untouched. +3 regression tests (return in <1s; would hang without the fix).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 25, 2026
…an't hang capture

run_streaming's CaptureOnly path read child pipes to EOF. When the direct child
exits but leaves a descendant holding the captured stdout/stderr open (e.g.
'ng build' leaves an esbuild --service grandchild on node's stderr; dotnet leaves
MSBuild/NuGet daemons — issue rtk-ai#2320), the pipe never EOFs and rtk hangs forever.

Spawn background reader threads that drain each pipe into a shared buffer, wait on
the DIRECT child, then bound the post-exit drain: stop when both readers signal EOF,
when output stops growing for STREAM_POST_EXIT_IDLE_GRACE (200ms), or at the hard
STREAM_POST_EXIT_MAX_DRAIN (2s) cap. A reader still blocked on a grandchild-held
pipe is detached via try_join_finished instead of joined.

Same root cause as upstream rtk-ai#2322, which fixes exec_capture; this ports the
child-exit + bounded-drain pattern to run_streaming, the path rtk-ai#2322 leaves
untouched. +3 regression tests (return in <1s; would hang without the fix).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

run_streaming's CaptureOnly path read child pipes to EOF. When the direct child
exits but leaves a descendant holding the captured stdout/stderr open (e.g.
'ng build' leaves an esbuild --service grandchild on node's stderr; dotnet leaves
MSBuild/NuGet daemons — issue rtk-ai#2320), the pipe never EOFs and rtk hangs forever.

Spawn background reader threads that drain each pipe into a shared buffer, wait on
the DIRECT child, then bound the post-exit drain: stop when both readers signal EOF,
when output stops growing for STREAM_POST_EXIT_IDLE_GRACE (200ms), or at the hard
STREAM_POST_EXIT_MAX_DRAIN (2s) cap. A reader still blocked on a grandchild-held
pipe is detached via try_join_finished instead of joined.

Same root cause as upstream rtk-ai#2322, which fixes exec_capture; this ports the
child-exit + bounded-drain pattern to run_streaming, the path rtk-ai#2322 leaves
untouched. +3 regression tests (return in <1s; would hang without the fix).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

run_streaming's CaptureOnly path read child pipes to EOF. When the direct child
exits but leaves a descendant holding the captured stdout/stderr open (e.g.
'ng build' leaves an esbuild --service grandchild on node's stderr; dotnet leaves
MSBuild/NuGet daemons — issue rtk-ai#2320), the pipe never EOFs and rtk hangs forever.

Spawn background reader threads that drain each pipe into a shared buffer, wait on
the DIRECT child, then bound the post-exit drain: stop when both readers signal EOF,
when output stops growing for STREAM_POST_EXIT_IDLE_GRACE (200ms), or at the hard
STREAM_POST_EXIT_MAX_DRAIN (2s) cap. A reader still blocked on a grandchild-held
pipe is detached via try_join_finished instead of joined.

Same root cause as upstream rtk-ai#2322, which fixes exec_capture; this ports the
child-exit + bounded-drain pattern to run_streaming, the path rtk-ai#2322 leaves
untouched. +3 regression tests (return in <1s; would hang without the fix).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
@pidefrem

Copy link
Copy Markdown

The "wait on the direct child, not pipe EOF" approach is exactly right. Heads-up that there's a second capture path with the identical bug this PR doesn't touch: exec_capture is fixed here, but run_streaming has the same EOF-blocking defect.

run_streaming drains the child's stdout/stderr to EOF before it returns, so when the direct child exits and a descendant has inherited the captured pipe, EOF never arrives — the same failure mode as #2320, just in the other function. This path is used by everything routed through the filtered/capture-only runner (long-running filtered commands), so the hang persists there even after this PR merges.

Repro (the #2320 topology — direct child exits, grandchild lingers): a tool whose direct child exits while a daemon it spawned keeps the captured pipe open — e.g. dotnet's MSBuild node / NuGet auth-plugin daemon (the #2320 case), or in a minimal shell form:

rtk run sh -c '(sleep 5) & echo done; exit 0'
# direct child (sh) exits immediately; the `sleep 5` grandchild holds the pipe →
# run_streaming blocks ~5s (or forever with a real long-lived daemon) instead of
# returning `done` + exit 0 promptly.

The fix that worked for me mirrors this PR's pattern on run_streaming: read each pipe on a background thread into a shared buffer, wait() the direct child, then bound the post-exit drain — stop when both readers EOF, when output goes idle for a short grace window, or at a hard cap — and detach (don't join) a reader still blocked on a grandchild-held pipe. Constants/naming kept parallel to this PR so it reads as the sibling fix.

I have it implemented and tested on my fork — commit 1d4409a on branch fix/stream-pipe-eof-drain, with a regression test (child exits while a grandchild holds the pipe). Would you be open to extending this PR to cover run_streaming too, so both capture paths are fixed together? Happy to supply the streaming-branch diff or open it as a PR against your branch.

@fengjikui
fengjikui force-pushed the fix/dotnet-capture-orphan-pipes branch from 3fb0d3f to 18427d4 Compare June 26, 2026 11:58
@fengjikui

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed pointer. I verified the sibling run_streaming path had the same EOF-blocking shape and extended this PR to cover it too.

Updated branch now includes:

  • bounded post-exit drain for run_streaming CaptureOnly/Buffered path
  • bounded idle handling for the live Streaming path
  • regression coverage for both exec_capture and run_streaming when a grandchild keeps the pipe open

Local validation:

  • cargo fmt --check
  • cargo test core::stream::tests (41 passed)

pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jun 26, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
@pidefrem

Copy link
Copy Markdown

Thanks for extending this to cover run_streaming as well — both capture paths fixed together is exactly the right shape.

One heads-up: this PR is currently showing conflicting against develop. The branch head is a bit behind develop now — in particular it predates the grep-faithful-engine rework (#2641), which renamed src/cmds/system/grep_cmd.rs → search.rs and reshaped a few neighbouring files, so a straight rebase will hit conflicts that aren't really about the capture fix.

To make the rebase easier, I re-applied the same fix (both exec_capture and run_streaming, bounded post-exit drain) on top of current develop on my fork — it's conflict-free there and the stream suite is green:

Feel free to cherry-pick or diff against it as a reference for the rebase — whatever's least work for you. Happy to open it as a separate compare link if that helps.

@fengjikui
fengjikui force-pushed the fix/dotnet-capture-orphan-pipes branch from 18427d4 to b4742f3 Compare June 27, 2026 00:02
@fengjikui

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto current develop and resolved the conflict in src/core/stream.rs using the same bounded-drain shape.

Current head: b4742f320be9c379e05fa0ba0fc3787dc0242c5c

Local validation:

  • cargo fmt --check
  • cargo test core::stream::tests (53 passed)

The PR is back to mergeable on GitHub; CLA remains green.

pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 18, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 22, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 22, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 22, 2026
…an't hang capture

When the direct child exits but a detached descendant keeps the captured pipe
open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild),
reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming
with background reader threads plus a bounded post-exit drain: once the direct child
is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still
blocked on a descendant-held pipe.

Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581):
readers accumulate raw bytes, collapse_terminal_control is applied to the final
buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation.

This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the
exec_capture half only. See brief 004 (issue rtk-ai#2320).
pidefrem added a commit to pidefrem/rtk that referenced this pull request Jul 22, 2026
The buffered capture path used by git/docker/wget/dotnet/ccusage still
called cmd.output(), which reads both pipes to EOF — so a descendant that
inherits the captured pipe and outlives the direct child (the same
topology brief 004 fixes in run_streaming) hangs capture until the pipe
EOFs. Rewire exec_capture to spawn background readers and bound the
post-exit drain via the existing spawn_capture_reader/drain_capture_readers
helpers.

Adopts the exec_capture half of upstream rtk-ai#2322 (the author fixed both
sites); our re-derived branch had only carried the run_streaming half.
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk dotnet build/test/restore hangs forever when a long-lived child daemon (NuGet auth plugin / MSBuild node) inherits the captured stdout/stderr pipe

2 participants