add graceful process termination on windows (#82)

This commit is contained in:
Grigorii Khvatskii
2025-03-25 18:26:33 -04:00
committed by GitHub
parent 84e2c07a7e
commit 4c3aa40564
3 changed files with 26 additions and 1 deletions

View File

@@ -304,7 +304,9 @@ func (p *Process) stopCommand(sigtermTTL time.Duration) {
return
}
p.cmd.Process.Signal(syscall.SIGTERM)
if err := p.terminateProcess(); err != nil {
fmt.Fprintf(p.logMonitor, "!!! failed to gracefully terminate process [%s]: %v\n", p.ID, err)
}
select {
case <-sigtermTimeout.Done():

9
proxy/process_stop.go Normal file
View File

@@ -0,0 +1,9 @@
//go:build !windows
package proxy
import "syscall"
func (p *Process) terminateProcess() error {
return p.cmd.Process.Signal(syscall.SIGTERM)
}

View File

@@ -0,0 +1,14 @@
//go:build windows
package proxy
import (
"fmt"
"os/exec"
)
func (p *Process) terminateProcess() error {
pid := fmt.Sprintf("%d", p.cmd.Process.Pid)
cmd := exec.Command("taskkill", "/f", "/t", "/pid", pid)
return cmd.Run()
}