fix(auth): harden unified diagnostic execution
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//go:build !windows
|
||||
|
||||
package compose
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
const gracefulTerminationBound = 500 * time.Millisecond
|
||||
const finalTerminationBound = 2 * time.Second
|
||||
|
||||
func configureProcess(command *exec.Cmd) {
|
||||
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
|
||||
func terminateProcess(command *exec.Cmd, done <-chan error) error {
|
||||
if command.Process == nil {
|
||||
return nil
|
||||
}
|
||||
_ = syscall.Kill(-command.Process.Pid, syscall.SIGINT)
|
||||
select {
|
||||
case <-done:
|
||||
return nil
|
||||
case <-time.After(gracefulTerminationBound):
|
||||
}
|
||||
_ = syscall.Kill(-command.Process.Pid, syscall.SIGKILL)
|
||||
_ = command.Process.Kill()
|
||||
select {
|
||||
case <-done:
|
||||
return nil
|
||||
case <-time.After(finalTerminationBound):
|
||||
return errors.New("Docker command could not be reaped")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user