From 8cd4fe0243b443e9e73758b55635f49dee094349 Mon Sep 17 00:00:00 2001 From: Darren Stahl Date: Fri, 31 Mar 2017 10:59:00 -0700 Subject: [PATCH] Wait to delete container when restoring on Windows Signed-off-by: Darren Stahl Upstream-commit: dbdc8bbee4a26093e6342f93bb63a09fbe850f58 Component: engine --- .../engine/libcontainerd/client_windows.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/engine/libcontainerd/client_windows.go b/components/engine/libcontainerd/client_windows.go index b7c6e1906c..3d59e944f8 100644 --- a/components/engine/libcontainerd/client_windows.go +++ b/components/engine/libcontainerd/client_windows.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "syscall" + "time" "golang.org/x/net/context" @@ -567,10 +568,18 @@ func (clnt *client) Restore(containerID string, _ StdioCallback, unusedOnWindows // We explicitly just log a warning if the terminate fails. // Then we tell the backend the container exited. if hc, err := hcsshim.OpenContainer(containerID); err == nil { - if err := hc.Terminate(); err != nil { - if !hcsshim.IsPending(err) { - logrus.Warnf("libcontainerd: failed to terminate %s on restore - %q", containerID, err) - } + const terminateTimeout = time.Minute * 2 + err := hc.Terminate() + + if hcsshim.IsPending(err) { + err = hc.WaitTimeout(terminateTimeout) + } else if hcsshim.IsAlreadyStopped(err) { + err = nil + } + + if err != nil { + logrus.Warnf("libcontainerd: failed to terminate %s on restore - %q", containerID, err) + return err } } return clnt.backend.StateChanged(containerID, StateInfo{