fix: clean command process groups on parent death#2125
Conversation
|
Caution Review failedThe pull request is closed. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds parent-process-exit monitoring (Unix watchdog, Windows no-op), integrates watcher into commandExecutor.Run after cmd.Start(), defers watcher stop, and adds a Unix integration test verifying process-group cleanup. Also makes a GitHub-dispatch worker cancellation test deterministic by signaling via a channel. ChangesParent Exit Watcher
GitHub Dispatch Worker Test
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/runtime/builtin/command/command_test.go`:
- Around line 421-438: The t.Cleanup handlers unconditionally send SIGKILL which
can hit a reused PID/group; modify the cleanup logic around cmd and scriptPID to
avoid killing already-terminated processes: after you explicitly stop/wait the
helper, clear or nil out cmd (or set cmd.Process = nil) and set scriptPID = 0,
and update the t.Cleanup closures for the cmd block (using cmd and
cmdutil.KillProcessGroup) and the script block (using syscall.Kill and
pidFile/scriptPID) to first check liveness (e.g., cmd != nil && cmd.Process !=
nil for the command, and scriptPID > 0 plus a syscall/OS check that the process
group exists) before sending signals, so cleanup only signals live processes and
avoids affecting reused PIDs.
- Around line 400-492: The parent-death test uses Unix-only process-group
semantics (syscall.Kill(-pid,...)) so move the
TestCommandExecutor_CleansProcessGroupWhenParentDies,
runCommandParentDeathHelper, and processGroupAlive helpers into a new file named
command_unix_test.go and add a build constraint line //go:build !windows (and
the matching +build comment if you want older toolchains) at the top; ensure the
test and helper functions (TestCommandExecutor_CleansProcessGroupWhenParentDies,
runCommandParentDeathHelper, processGroupAlive) and any required imports are
copied over and any Windows-specific skips removed since the file itself is
Unix-only.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 513184bb-d8d0-45ee-a097-098a7e5472de
📒 Files selected for processing (4)
internal/cmn/cmdutil/parent_exit_watcher_unix.gointernal/cmn/cmdutil/parent_exit_watcher_windows.gointernal/runtime/builtin/command/command.gointernal/runtime/builtin/command/command_test.go
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/runtime/builtin/command/command_unix_test.go (1)
34-34: 💤 Low valueOptional: anchor the
-test.runregex to prevent unintended matches.
-test.runis an unanchored regular expression — because it is unanchored, an empty expression matches any string. Without anchors any future test whose name contains this substring would also be launched inside the helper subprocess, exercising unexpected code paths.🔧 Proposed fix
- cmd := exec.Command(os.Args[0], "-test.run=TestCommandExecutor_CleansProcessGroupWhenParentDies") + cmd := exec.Command(os.Args[0], "-test.run=^TestCommandExecutor_CleansProcessGroupWhenParentDies$")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/runtime/builtin/command/command_unix_test.go` at line 34, The test helper invocation builds a subprocess with "-test.run=TestCommandExecutor_CleansProcessGroupWhenParentDies" which is an unanchored regex and may match unintended tests; update the argument passed to exec.Command (where the string is constructed in the test setup for TestCommandExecutor_CleansProcessGroupWhenParentDies) to anchor the regex (e.g. wrap with ^ and $) so it only matches the exact test name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/runtime/builtin/command/command_unix_test.go`:
- Line 34: The test helper invocation builds a subprocess with
"-test.run=TestCommandExecutor_CleansProcessGroupWhenParentDies" which is an
unanchored regex and may match unintended tests; update the argument passed to
exec.Command (where the string is constructed in the test setup for
TestCommandExecutor_CleansProcessGroupWhenParentDies) to anchor the regex (e.g.
wrap with ^ and $) so it only matches the exact test name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6770c4e-629d-4013-b9ab-9d8ffe281f26
📒 Files selected for processing (1)
internal/runtime/builtin/command/command_unix_test.go
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/runtime/builtin/command/command_unix_test.go`:
- Around line 88-127: The test runCommandParentDeathHelper currently uses
require.NoError(t, err) on the value received from errCh but Run(ctx) may
legitimately return a non-nil "killed" error when the parent-exit watcher kills
the script; relax this assertion to accept either a nil error or an error whose
message indicates the process was killed (e.g., check err == nil ||
strings.Contains(err.Error(), "killed") or inspect os.IsProcessDone/exit
status), replacing the require.NoError(t, err) in the goroutine receiver block
to tolerate the killed-exit path while still failing on unexpected errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1ea49d87-1c66-4997-a14b-80905545909f
📒 Files selected for processing (1)
internal/runtime/builtin/command/command_unix_test.go
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
♻️ Duplicate comments (1)
internal/runtime/builtin/command/command_unix_test.go (1)
121-128:⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
require.Contains(t, err.Error(), "killed")still stricter than the past suggestion to just log the error.This select block is only reachable in the narrow race window where the watcher kills the script before the parent kills the helper. In that window
err.Error()will be"signal: killed"(SIGKILL from the watcher), so the check is usually safe — but ifcommandExec.Runwraps the error with a non-"killed" prefix, or the context is cancelled first (producing"context canceled"), the assertion fails spuriously. The past review recommended dropping the assertion tot.Logf.💡 Proposed fix to match the past comment's suggestion
select { case err := <-errCh: if err != nil { - require.Contains(t, err.Error(), "killed") + t.Logf("commandExec.Run returned: %v (expected if killed by watcher)", err) } case <-time.After(30 * time.Second):🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/runtime/builtin/command/command_unix_test.go` around lines 121 - 128, The test's select branch currently asserts that err.Error() contains "killed", which is brittle; replace the strict assertion in the case receiving from errCh with a non-failing logger (e.g. call t.Logf or t.Log) that records the error value instead of require.Contains so the test won't fail if commandExec.Run wraps the error or the context is canceled; locate the select that reads from errCh in the test (the block containing require.Contains(t, err.Error(), "killed")) and change it to log the error when non-nil.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@internal/runtime/builtin/command/command_unix_test.go`:
- Around line 121-128: The test's select branch currently asserts that
err.Error() contains "killed", which is brittle; replace the strict assertion in
the case receiving from errCh with a non-failing logger (e.g. call t.Logf or
t.Log) that records the error value instead of require.Contains so the test
won't fail if commandExec.Run wraps the error or the context is canceled; locate
the select that reads from errCh in the test (the block containing
require.Contains(t, err.Error(), "killed")) and change it to log the error when
non-nil.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: df694e2f-57ae-43d8-a55c-b207ea96335d
📒 Files selected for processing (2)
internal/runtime/builtin/command/command_unix_test.gointernal/service/scheduler/github_dispatch_test.go
0d7ea15 to
e3e9f70
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Testing
Summary by CodeRabbit