From b819ffdb2079bf2e805f8ca2ed84f184fe601269 Mon Sep 17 00:00:00 2001 From: Darren Stahl Date: Tue, 7 Mar 2017 16:24:34 -0800 Subject: [PATCH] Stop holding client container lock during shutdown Signed-off-by: Darren Stahl --- libcontainerd/container_windows.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libcontainerd/container_windows.go b/libcontainerd/container_windows.go index 9b1965099a..753d2f2f92 100644 --- a/libcontainerd/container_windows.go +++ b/libcontainerd/container_windows.go @@ -201,9 +201,18 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err logrus.Debugln("libcontainerd: waitExit() on pid", process.systemPid) exitCode := ctr.waitProcessExitCode(process) - // Lock the container while shutting down + // Lock the container while removing the process/container from the list ctr.client.lock(ctr.containerID) + if !isFirstProcessToStart { + ctr.cleanProcess(process.friendlyName) + } else { + ctr.client.deleteContainer(ctr.containerID) + } + + // Unlock here so other threads are unblocked + ctr.client.unlock(ctr.containerID) + // Assume the container has exited si := StateInfo{ CommonStateInfo: CommonStateInfo{ @@ -218,7 +227,6 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err // But it could have been an exec'd process which exited if !isFirstProcessToStart { si.State = StateExitProcess - ctr.cleanProcess(process.friendlyName) } else { updatePending, err := ctr.hcsContainer.HasPendingUpdates() if err != nil { @@ -236,20 +244,12 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err if err := ctr.hcsContainer.Close(); err != nil { logrus.Error(err) } - - // Remove process from list if we have exited - if si.State == StateExit { - ctr.client.deleteContainer(ctr.containerID) - } } if err := process.hcsProcess.Close(); err != nil { logrus.Errorf("libcontainerd: hcsProcess.Close(): %v", err) } - // Unlock here before we call back into the daemon to update state - ctr.client.unlock(ctr.containerID) - // Call into the backend to notify it of the state change. logrus.Debugf("libcontainerd: waitExit() calling backend.StateChanged %+v", si) if err := ctr.client.backend.StateChanged(ctr.containerID, si); err != nil {