Skip to content

Commit db56873

Browse files
committed
docker-proxy cannot exit after send SIGINT
1 parent 3fb133e commit db56873

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

portmapper/proxy.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net"
88
"os"
99
"os/exec"
10+
"syscall"
1011
"time"
1112

1213
"github.com/ishidawataru/sctp"
@@ -65,10 +66,23 @@ func (p *proxyCommand) Start() error {
6566

6667
func (p *proxyCommand) Stop() error {
6768
if p.cmd.Process != nil {
68-
if err := p.cmd.Process.Signal(os.Interrupt); err != nil {
69+
if err := p.cmd.Process.Signal(syscall.SIGTERM); err != nil {
6970
return err
7071
}
71-
return p.cmd.Wait()
72+
73+
waitChan := make(chan error)
74+
go func() {
75+
waitChan <- p.cmd.Wait()
76+
}()
77+
78+
select {
79+
case result := <-waitChan:
80+
return result
81+
case <-time.After(15 * time.Second):
82+
if err := p.cmd.Process.Signal(os.Kill); err != nil {
83+
return err
84+
}
85+
}
7286
}
7387
return nil
7488
}

0 commit comments

Comments
 (0)