Browse code

Wait to delete container when restoring on Windows

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

Darren Stahl authored on 2017/04/01 02:59:00
Showing 1 changed files
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"path/filepath"
10 10
 	"strings"
11 11
 	"syscall"
12
+	"time"
12 13
 
13 14
 	"golang.org/x/net/context"
14 15
 
... ...
@@ -567,10 +568,18 @@ func (clnt *client) Restore(containerID string, _ StdioCallback, unusedOnWindows
567 567
 	// We explicitly just log a warning if the terminate fails.
568 568
 	// Then we tell the backend the container exited.
569 569
 	if hc, err := hcsshim.OpenContainer(containerID); err == nil {
570
-		if err := hc.Terminate(); err != nil {
571
-			if !hcsshim.IsPending(err) {
572
-				logrus.Warnf("libcontainerd: failed to terminate %s on restore - %q", containerID, err)
573
-			}
570
+		const terminateTimeout = time.Minute * 2
571
+		err := hc.Terminate()
572
+
573
+		if hcsshim.IsPending(err) {
574
+			err = hc.WaitTimeout(terminateTimeout)
575
+		} else if hcsshim.IsAlreadyStopped(err) {
576
+			err = nil
577
+		}
578
+
579
+		if err != nil {
580
+			logrus.Warnf("libcontainerd: failed to terminate %s on restore - %q", containerID, err)
581
+			return err
574 582
 		}
575 583
 	}
576 584
 	return clnt.backend.StateChanged(containerID, StateInfo{