diff --git a/portmapper/proxy.go b/portmapper/proxy.go index 12e4122c05..4cef8cb494 100644 --- a/portmapper/proxy.go +++ b/portmapper/proxy.go @@ -7,6 +7,7 @@ import ( "net" "os" "os/exec" + "syscall" "time" "github.com/ishidawataru/sctp" @@ -65,10 +66,23 @@ func (p *proxyCommand) Start() error { func (p *proxyCommand) Stop() error { if p.cmd.Process != nil { - if err := p.cmd.Process.Signal(os.Interrupt); err != nil { + if err := p.cmd.Process.Signal(syscall.SIGTERM); err != nil { return err } - return p.cmd.Wait() + + waitChan := make(chan error) + go func() { + waitChan <- p.cmd.Wait() + }() + + select { + case result := <-waitChan: + return result + case <-time.After(15 * time.Second): + if err := p.cmd.Process.Signal(os.Kill); err != nil { + return err + } + } } return nil }