Skip to content

Commit

Permalink
runner: better handle the competition between SIGTERM and SIGKILL
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Aug 19, 2024
1 parent 6dc7ac8 commit 6502565
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/runner/cmd_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ func command(cmd string) (*exec.Cmd, func() error) {
pgid := -c.Process.Pid
_ = syscall.Kill(pgid, syscall.SIGTERM)
exited := make(chan struct{})
defer close(exited)
time.AfterFunc(5*time.Second, func() {
select {
case <-exited:
return
default:
_ = syscall.Kill(pgid, syscall.SIGKILL)
}
})
_ = c.Wait()
go func() {
defer close(exited)
_, _ = c.Process.Wait()
}()
select {
case <-exited:
case <-time.After(5 * time.Second):
_ = syscall.Kill(pgid, syscall.SIGKILL)
}
return nil
}
}

0 comments on commit 6502565

Please sign in to comment.