Skip to content

Commit

Permalink
Merge pull request moby#20934 from icecrime/20543_debugging
Browse files Browse the repository at this point in the history
Fix race condition on daemon shutdown (moby#20543)
  • Loading branch information
calavera committed Mar 4, 2016
2 parents ea738c6 + ad2fa39 commit 2af84d8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions daemon/execdriver/native/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
if err != nil {
return execdriver.ExitStatus{ExitCode: -1}, err
}

if err := cont.Start(p); err != nil {
return execdriver.ExitStatus{ExitCode: -1}, err
}
d.Lock()
d.activeContainers[c.ID] = cont
d.Unlock()
Expand All @@ -167,10 +171,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
d.cleanContainer(c.ID)
}()

if err := cont.Start(p); err != nil {
return execdriver.ExitStatus{ExitCode: -1}, err
}

//close the write end of any opened pipes now that they are dup'ed into the container
for _, writer := range writers {
writer.Close()
Expand Down Expand Up @@ -302,6 +302,9 @@ func (d *Driver) Kill(c *execdriver.Command, sig int) error {
if err != nil {
return err
}
if state.InitProcessPid == -1 {
return fmt.Errorf("avoid sending signal %d to container %s with pid -1", sig, c.ID)
}
return syscall.Kill(state.InitProcessPid, syscall.Signal(sig))
}

Expand Down

0 comments on commit 2af84d8

Please sign in to comment.