Enforce --timeout when a command leaves a child running - #218
Conversation
Stdout and Stderr are buffers rather than files, so os/exec pipes them and
Wait blocks until the pipe reaches EOF. CommandContext kills only the direct
child, so a grandchild holding the write end keeps the pipe open and the
deadline never applies.
A version command that daemonizes — a service wrapper, an agent, a docker
shim — therefore hung the check indefinitely. Measured with a script that
backgrounds a sleep before exiting:
preflight cmd ./slowchild --timeout 2s 31s elapsed
In a container entrypoint that is a permanent stall rather than a failed
check, which is the worse outcome: a failure is reported, a hang is not.
Setting cmd.WaitDelay bounds Wait after cancellation. Same command now
returns in 1s, and commands that exit normally are unaffected.
|
Warning Review limit reached
Next review available in: 48 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #218 +/- ##
=======================================
Coverage 93.10% 93.11%
=======================================
Files 49 49
Lines 1872 1873 +1
=======================================
+ Hits 1743 1744 +1
Misses 93 93
Partials 36 36
🚀 New features to boost your workflow:
|
--timeoutwas unenforceable against any version command that leaves a background child holding stdout. Measured with a script that backgrounds asleepbefore exiting:Why
Stdout/Stderrarebytes.Buffer, not*os.File, soos/execcreates pipes and a copying goroutine, andWaitblocks until the pipe reaches EOF.CommandContextkills only the direct child — a grandchild holding the write end keeps the pipe open, so the deadline never takes effect.In a container entrypoint this is worse than a failed check: a failure is reported and the container stops; a hang just sits there. Realistic triggers are version commands that daemonize — a service wrapper, a monitoring agent, a
dockershim.Fix
cmd.WaitDelay = time.Second, which bounds how longWaitblocks after cancellation. Two lines including the constant.Tests
runner_unix_test.go, written first and confirmed red — it hit the 15s bound and reported "the 200ms timeout was not enforced", then passed in 1.11s after the fix.Two cases:
WaitDelaydoesn't truncate healthy runsUnix-tagged, since it needs a shell script. It's self-contained — no shared helpers cross the build tag, which is the mistake #213 fixed in
resourcecheck.Note
TestTCPCommandfails on this branch. That's the127.0.0.1:1flake fixed in #217, which isn't merged yet — unrelated to this change, and this branch only touchespkg/cmdcheck.