fix(auth): harden diagnostic cleanup races

This commit is contained in:
2026-08-17 18:41:40 +02:00
parent af16464e68
commit d12b629420
7 changed files with 387 additions and 36 deletions
@@ -0,0 +1,41 @@
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
}
}