Repository navigation
Conversation
…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).
…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).
…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).
…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).
…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).
…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).
…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).
…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).
…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).
|
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:
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: The fix that worked for me mirrors this PR's pattern on I have it implemented and tested on my fork — commit |
3fb0d3f to
18427d4
Compare
|
Thanks for the detailed pointer. I verified the sibling Updated branch now includes:
Local validation:
|
…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).
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.
…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).
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.
|
Thanks for extending this to cover One heads-up: this PR is currently showing conflicting against To make the rebase easier, I re-applied the same fix (both
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. |
18427d4 to
b4742f3
Compare
|
Rebased this branch onto current Current head: Local validation:
The PR is back to mergeable on GitHub; CLA remains green. |
…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).
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.
…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).
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.
…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).
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.
…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).
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.
…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).
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.
…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).
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.
…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).
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.
|
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. |
|
Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you! |
Fixes #2320
Summary
Command::output()inexec_capturewith explicit spawn/wait plus background stdout/stderr readersWhy
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 directdotnetchild 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 --checkcargo test core::stream::tests::test_exec_capture_returns_after_child_exits_when_grandchild_holds_pipe -- --nocapturecargo test core::stream::tests::test_exec_capture -- --nocapturecargo test core::stream -- --nocapturecargo clippy --all-targets -- -D warningscargo testgit diff --check