Files
ThothII/tools/tht/internal/compose/process_termination.go
T

42 lines
789 B
Go

package compose
import "time"
// terminateWindowsProcess reports a reap failure only when the process has not exited within the
// final bound. taskkill and Process.Kill can both race with a child that has already been reaped.
func terminateWindowsProcess(
done <-chan error,
terminateTree func() error,
terminateDirect func() error,
bound time.Duration,
) error {
if processReaped(done) {
return nil
}
_ = terminateTree()
if processReaped(done) {
return nil
}
_ = terminateDirect()
if processReaped(done) {
return nil
}
timer := time.NewTimer(bound)
defer timer.Stop()
select {
case <-done:
return nil
case <-timer.C:
return ErrProcessReap
}
}
func processReaped(done <-chan error) bool {
select {
case <-done:
return true
default:
return false
}
}