From f7fe9669ce2bb99dc34d67db3783c0b126ee4510 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 10 Jan 2014 17:25:32 -0800 Subject: [PATCH] Fix race in set running Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) Upstream-commit: 77936ba1a1ff404b75ae8a34c6d4e280c23d9144 Component: engine --- components/engine/container.go | 8 ++++++-- components/engine/execdriver/lxc/driver.go | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/engine/container.go b/components/engine/container.go index 856ee352d6..924727bd3a 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -760,6 +760,7 @@ func (container *Container) Start() (err error) { return err } container.waitLock = make(chan struct{}) + container.State.SetRunning(0) go container.monitor() if container.Config.Tty { @@ -771,7 +772,9 @@ func (container *Container) Start() (err error) { return err } - container.State.SetRunning(container.process.Pid()) + // TODO: @crosbymichael @creack + // find a way to update this + // container.State.SetRunning(container.process.Pid()) container.ToDisk() return nil } @@ -1176,6 +1179,8 @@ 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 @@ -1185,7 +1190,6 @@ 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/components/engine/execdriver/lxc/driver.go b/components/engine/execdriver/lxc/driver.go index 0f7a4cacf8..62b60deb61 100644 --- a/components/engine/execdriver/lxc/driver.go +++ b/components/engine/execdriver/lxc/driver.go @@ -123,7 +123,6 @@ func (d *driver) Wait(id string, duration time.Duration) error { func (d *driver) kill(c *execdriver.Process, sig int) error { output, err := exec.Command("lxc-kill", "-n", c.ID, strconv.Itoa(sig)).CombinedOutput() if err != nil { - fmt.Printf("--->%s\n", output) return fmt.Errorf("Err: %s Output: %s", err, output) } return nil