From e53c739014a514f880293fb520310d11e48d157e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 9 Apr 2013 17:40:02 -0700 Subject: [PATCH] Make sure all containers (even previously stopped) get a correct wait lock Upstream-commit: 9f83b9df2256c7b34453d5da85c17fae516ee3a4 Component: engine --- components/engine/runtime.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/engine/runtime.go b/components/engine/runtime.go index 7971fe4f48..24194f74ad 100644 --- a/components/engine/runtime.go +++ b/components/engine/runtime.go @@ -134,6 +134,9 @@ func (runtime *Runtime) Register(container *Container) error { return err } + // init the wait lock + container.waitLock = make(chan struct{}) + // FIXME: if the container is supposed to be running but is not, auto restart it? // if so, then we need to restart monitor and init a new lock // If the container is supposed to be running, make sure of it @@ -150,6 +153,14 @@ func (runtime *Runtime) Register(container *Container) error { } } } + + // If the container is not running or just has been flagged not running + // then close the wait lock chan (will be reset upon start) + if !container.State.Running { + close(container.waitLock) + } + + // Even if not running, we init the lock (prevents races in start/stop/kill) container.State.initLock() container.runtime = runtime