Skip to content

Commit

Permalink
docker-proxy cannot exit after send SIGINT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mingfukuang committed Sep 4, 2019
1 parent 3fb133e commit 5eb7f01
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 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,26 @@ 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()
}()

t := time.NewTimer(15 * time.Second)
defer t.Stop()

select {
case result := <-waitChan:
return result
case <-t.C:
if err := p.cmd.Process.Signal(os.Kill); err != nil {
return err
}
}
}
return nil
}
Expand Down

0 comments on commit 5eb7f01

Please sign in to comment.