Browse Source

Wait to delete container when restoring on Windows

Signed-off-by: Darren Stahl <darst@microsoft.com>
Darren Stahl 8 years ago
parent
commit
dbdc8bbee4
1 changed files with 13 additions and 4 deletions
  1. 13 4
      libcontainerd/client_windows.go

+ 13 - 4
libcontainerd/client_windows.go

@@ -9,6 +9,7 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"strings"
 	"strings"
 	"syscall"
 	"syscall"
+	"time"
 
 
 	"golang.org/x/net/context"
 	"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.
 	// We explicitly just log a warning if the terminate fails.
 	// Then we tell the backend the container exited.
 	// Then we tell the backend the container exited.
 	if hc, err := hcsshim.OpenContainer(containerID); err == nil {
 	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{
 	return clnt.backend.StateChanged(containerID, StateInfo{