From feacb1205b2cf9166e75e707d7b5fa2d09e80e03 Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 5 May 2016 19:49:59 -0700 Subject: [PATCH] Windows: Terminate on failed shutdown Signed-off-by: John Howard --- libcontainerd/client_windows.go | 14 +++++++++++++- libcontainerd/container_windows.go | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index 22aa07ead8..1a96d0b6f7 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -362,7 +362,19 @@ func (clnt *client) Signal(containerID string, sig int) error { } // Shutdown the compute system - if err := hcsshim.ShutdownComputeSystem(containerID, hcsshim.TimeoutInfinite, context); err != nil { + const shutdownTimeout = 5 * 60 * 1000 // 5 minutes + if err := hcsshim.ShutdownComputeSystem(containerID, shutdownTimeout, context); err != nil { + if herr, ok := err.(*hcsshim.HcsError); !ok || + (herr.Err != hcsshim.ERROR_SHUTDOWN_IN_PROGRESS && + herr.Err != ErrorBadPathname && + herr.Err != syscall.ERROR_PATH_NOT_FOUND) { + logrus.Debugf("signal - error from ShutdownComputeSystem %v on %s. Calling TerminateComputeSystem", err, containerID) + if err := hcsshim.TerminateComputeSystem(containerID, shutdownTimeout, "signal"); err != nil { + logrus.Debugf("signal - ignoring error from TerminateComputeSystem on %s %v", containerID, err) + } else { + logrus.Debugf("Successful TerminateComputeSystem after failed ShutdownComputeSystem on %s during signal %v", containerID, sig) + } + } logrus.Errorf("Failed to shutdown %s - %q", containerID, err) } } diff --git a/libcontainerd/container_windows.go b/libcontainerd/container_windows.go index 6b074f17d0..650fe73f09 100644 --- a/libcontainerd/container_windows.go +++ b/libcontainerd/container_windows.go @@ -185,7 +185,12 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr (herr.Err != hcsshim.ERROR_SHUTDOWN_IN_PROGRESS && herr.Err != ErrorBadPathname && herr.Err != syscall.ERROR_PATH_NOT_FOUND) { - logrus.Warnf("Ignoring error from ShutdownComputeSystem %s", err) + logrus.Debugf("waitExit - error from ShutdownComputeSystem on %s %v. Calling TerminateComputeSystem", ctr.containerCommon, err) + if err := hcsshim.TerminateComputeSystem(ctr.containerID, shutdownTimeout, "waitExit"); err != nil { + logrus.Debugf("waitExit - ignoring error from TerminateComputeSystem %s %v", ctr.containerID, err) + } else { + logrus.Debugf("Successful TerminateComputeSystem after failed ShutdownComputeSystem on %s in waitExit", ctr.containerID) + } } } else { logrus.Debugf("Completed shutting down container %s", ctr.containerID)