Fix race in TestRun

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-01-10 16:11:19 -08:00
parent 8b60273f76
commit ad9710685c
3 changed files with 11 additions and 5 deletions

View File

@ -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() {

View File

@ -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
}

View File

@ -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)