Skip to content

Commit

Permalink
docker-proxy cannot exit after send SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
mingfukuang committed Jul 20, 2019
1 parent 3fb133e commit db56873
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions portmapper/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"os"
"os/exec"
"syscall"
"time"

"github.com/ishidawataru/sctp"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit db56873

Please sign in to comment.