Skip to content

Commit 3b7449f

Browse files
rremerRoyce Remer
authored andcommitted
fix(process): Always check ProcessState before reaping by pid
Assisted-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Royce Remer <royceremer@gmail.com>
1 parent 9e336b1 commit 3b7449f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

modules/process/command_unix.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ func (c *Cmd) onCancel() error {
2727
}
2828
sig := util.Iif(c.termGraceful, syscall.SIGTERM, syscall.SIGKILL)
2929
if sig == syscall.SIGTERM && c.Cmd.WaitDelay > 0 {
30-
pgid, delay := c.Process.Pid, c.Cmd.WaitDelay
30+
delay := c.Cmd.WaitDelay
3131
go func() {
3232
time.Sleep(delay)
33-
_ = syscall.Kill(-pgid, syscall.SIGKILL)
33+
_ = c.signalProcessGroup(syscall.SIGKILL)
3434
}()
3535
}
36-
// kill the whole process group
36+
return c.signalProcessGroup(sig)
37+
}
38+
39+
// signalProcessGroup sends sig to the process group, skipping if the process has already been reaped.
40+
func (c *Cmd) signalProcessGroup(sig syscall.Signal) error {
41+
if c.Cmd.ProcessState != nil {
42+
return nil
43+
}
3744
return syscall.Kill(-c.Process.Pid, sig)
3845
}

0 commit comments

Comments
 (0)