Skip to content

Commit 5eb7f01

Browse files
committed
docker-proxy cannot exit after send SIGINT
Signed-off-by: mingfukuang <[email protected]> When stop or delete one container with docker-proxy, stop container will call Unmap() to release port , func Unmap() need to acquire pm.lock.Lock() firstly, then stop docker-proxy, and then pm.lock.UnLock(). but some situation(cannot be reproduced), stop docker-proxy will hang on. Once one container cann't stop docker-proxy, above mentioned pm.lock cann't be released, so this container cann’t be stopped, Also all operation of this container could be hang on. Furthermore, if other containers enter stop or delete process, those containers also need to acquire the global pm.lock, and get stuck. As result, other operations to those containers also hang on, such as docker inspect, docker exec, etc. To fix this, I add protective measures to avoid the situation of global lock(pm.lock)cann't being released.
1 parent 3fb133e commit 5eb7f01

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

portmapper/proxy.go

Lines changed: 19 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,26 @@ 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+
t := time.NewTimer(15 * time.Second)
79+
defer t.Stop()
80+
81+
select {
82+
case result := <-waitChan:
83+
return result
84+
case <-t.C:
85+
if err := p.cmd.Process.Signal(os.Kill); err != nil {
86+
return err
87+
}
88+
}
7289
}
7390
return nil
7491
}

0 commit comments

Comments
 (0)