diff --git a/container.go b/container.go index 33e39815e5..80f9e34ac2 100644 --- a/container.go +++ b/container.go @@ -1171,7 +1171,6 @@ func (container *Container) monitor() { exitCode := container.process.GetExitCode() container.State.SetStopped(exitCode) - close(container.waitLock) if err := container.ToDisk(); err != nil { // FIXME: there is a race condition here which causes this to fail during the unit tests. // If another goroutine was waiting for Wait() to return before removing the container's root @@ -1181,6 +1180,7 @@ func (container *Container) monitor() { // FIXME: why are we serializing running state to disk in the first place? //log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err) } + close(container.waitLock) } func (container *Container) cleanup() { diff --git a/execdriver/driver.go b/execdriver/driver.go index 4a0f72dd08..94905a7b0d 100644 --- a/execdriver/driver.go +++ b/execdriver/driver.go @@ -44,6 +44,8 @@ func (c *Process) Pid() int { } func (c *Process) GetExitCode() int { + if c.ProcessState == nil { + return -1 + } return c.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() - return -1 } diff --git a/execdriver/lxc/driver.go b/execdriver/lxc/driver.go index e9bddf1af5..0f7a4cacf8 100644 --- a/execdriver/lxc/driver.go +++ b/execdriver/lxc/driver.go @@ -139,9 +139,13 @@ func (d *driver) waitForStart(c *execdriver.Process) error { // Note: The container can run and finish correctly before // the end of this loop for now := time.Now(); time.Since(now) < 5*time.Second; { - // If the process dies while waiting for it, just return - if c.ProcessState != nil && c.ProcessState.Exited() { - return nil + select { + case <-c.WaitLock: + // If the process dies while waiting for it, just return + if c.ProcessState != nil && c.ProcessState.Exited() { + return nil + } + default: } output, err = d.getInfo(c)