Browse code

Stop holding client container lock during shutdown

Signed-off-by: Darren Stahl <darst@microsoft.com>

Darren Stahl authored on 2017/03/08 09:24:34
Showing 1 changed files
... ...
@@ -201,9 +201,18 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err
201 201
 	logrus.Debugln("libcontainerd: waitExit() on pid", process.systemPid)
202 202
 
203 203
 	exitCode := ctr.waitProcessExitCode(process)
204
-	// Lock the container while shutting down
204
+	// Lock the container while removing the process/container from the list
205 205
 	ctr.client.lock(ctr.containerID)
206 206
 
207
+	if !isFirstProcessToStart {
208
+		ctr.cleanProcess(process.friendlyName)
209
+	} else {
210
+		ctr.client.deleteContainer(ctr.containerID)
211
+	}
212
+
213
+	// Unlock here so other threads are unblocked
214
+	ctr.client.unlock(ctr.containerID)
215
+
207 216
 	// Assume the container has exited
208 217
 	si := StateInfo{
209 218
 		CommonStateInfo: CommonStateInfo{
... ...
@@ -218,7 +227,6 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err
218 218
 	// But it could have been an exec'd process which exited
219 219
 	if !isFirstProcessToStart {
220 220
 		si.State = StateExitProcess
221
-		ctr.cleanProcess(process.friendlyName)
222 221
 	} else {
223 222
 		updatePending, err := ctr.hcsContainer.HasPendingUpdates()
224 223
 		if err != nil {
... ...
@@ -236,20 +244,12 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err
236 236
 		if err := ctr.hcsContainer.Close(); err != nil {
237 237
 			logrus.Error(err)
238 238
 		}
239
-
240
-		// Remove process from list if we have exited
241
-		if si.State == StateExit {
242
-			ctr.client.deleteContainer(ctr.containerID)
243
-		}
244 239
 	}
245 240
 
246 241
 	if err := process.hcsProcess.Close(); err != nil {
247 242
 		logrus.Errorf("libcontainerd: hcsProcess.Close(): %v", err)
248 243
 	}
249 244
 
250
-	// Unlock here before we call back into the daemon to update state
251
-	ctr.client.unlock(ctr.containerID)
252
-
253 245
 	// Call into the backend to notify it of the state change.
254 246
 	logrus.Debugf("libcontainerd: waitExit() calling backend.StateChanged %+v", si)
255 247
 	if err := ctr.client.backend.StateChanged(ctr.containerID, si); err != nil {