Fix process group signal escalation

This commit is contained in:
Virgil 2026-04-04 01:32:43 +00:00
parent ba4b0f1166
commit 1028e31ae5

View file

@ -251,7 +251,8 @@ func (p *Process) Signal(sig os.Signal) error {
// Some shells briefly ignore or defer the signal while they are still
// initialising child jobs. Retry a few times after short delays so the
// whole process group is more reliably terminated.
// whole process group is more reliably terminated. If the requested signal
// still does not stop the group, escalate to SIGKILL so callers do not hang.
go func(pid int, sig syscall.Signal, done <-chan struct{}) {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
@ -264,6 +265,13 @@ func (p *Process) Signal(sig os.Signal) error {
_ = syscall.Kill(-pid, sig)
}
}
select {
case <-done:
return
default:
_ = syscall.Kill(-pid, syscall.SIGKILL)
}
}(cmd.Process.Pid, sysSig, p.done)
return nil