1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 {
return c.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
if c.ProcessState == nil {
return -1
}
return c.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
}

View file

@ -139,10 +139,14 @@ 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; {
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)
if err != nil {