Skip to content

Commit e12550c

Browse files
committed
Check if Process non-nil before calling Kill
A bad interleaving could (and has - golang#391) cause the context cancellation select branch to run before the normal process termination branch.
1 parent f9e9408 commit e12550c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ func (c *monitoredCmd) run(ctx context.Context) error {
6363
return &timeoutError{c.timeout}
6464
}
6565
case <-ctx.Done():
66-
if err := c.cmd.Process.Kill(); err != nil {
67-
return &killCmdError{err}
66+
if c.cmd.Process != nil {
67+
if err := c.cmd.Process.Kill(); err != nil {
68+
return &killCmdError{err}
69+
}
6870
}
6971
return c.ctx.Err()
7072
case err := <-done:

0 commit comments

Comments
 (0)