Skip to content

Commit 4c3aa40

Browse files
authored
add graceful process termination on windows (#82)
1 parent 84e2c07 commit 4c3aa40

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

proxy/process.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ func (p *Process) stopCommand(sigtermTTL time.Duration) {
304304
return
305305
}
306306

307-
p.cmd.Process.Signal(syscall.SIGTERM)
307+
if err := p.terminateProcess(); err != nil {
308+
fmt.Fprintf(p.logMonitor, "!!! failed to gracefully terminate process [%s]: %v\n", p.ID, err)
309+
}
308310

309311
select {
310312
case <-sigtermTimeout.Done():

proxy/process_stop.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !windows
2+
3+
package proxy
4+
5+
import "syscall"
6+
7+
func (p *Process) terminateProcess() error {
8+
return p.cmd.Process.Signal(syscall.SIGTERM)
9+
}

proxy/process_stop_windows.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build windows
2+
3+
package proxy
4+
5+
import (
6+
"fmt"
7+
"os/exec"
8+
)
9+
10+
func (p *Process) terminateProcess() error {
11+
pid := fmt.Sprintf("%d", p.cmd.Process.Pid)
12+
cmd := exec.Command("taskkill", "/f", "/t", "/pid", pid)
13+
return cmd.Run()
14+
}

0 commit comments

Comments
 (0)