Browse code

Make sure all containers (even previously stopped) get a correct wait lock

Guillaume J. Charmes authored on 2013/04/10 09:40:02
Showing 1 changed files
... ...
@@ -134,6 +134,9 @@ func (runtime *Runtime) Register(container *Container) error {
134 134
 		return err
135 135
 	}
136 136
 
137
+	// init the wait lock
138
+	container.waitLock = make(chan struct{})
139
+
137 140
 	// FIXME: if the container is supposed to be running but is not, auto restart it?
138 141
 	//        if so, then we need to restart monitor and init a new lock
139 142
 	// If the container is supposed to be running, make sure of it
... ...
@@ -150,6 +153,14 @@ func (runtime *Runtime) Register(container *Container) error {
150 150
 			}
151 151
 		}
152 152
 	}
153
+
154
+	// If the container is not running or just has been flagged not running
155
+	// then close the wait lock chan (will be reset upon start)
156
+	if !container.State.Running {
157
+		close(container.waitLock)
158
+	}
159
+
160
+	// Even if not running, we init the lock (prevents races in start/stop/kill)
153 161
 	container.State.initLock()
154 162
 
155 163
 	container.runtime = runtime