Browse code

Windows: Cleanup HCS on restore

Signed-off-by: John Howard <jhoward@microsoft.com>

This ensures that any compute processes in HCS are cleanedup
during daemon restore. Note Windows cannot (currently) reconnect
to containers on restore.

John Howard authored on 2017/03/03 08:12:14
Showing 1 changed files
... ...
@@ -557,8 +557,22 @@ func (clnt *client) Stats(containerID string) (*Stats, error) {
557 557
 
558 558
 // Restore is the handler for restoring a container
559 559
 func (clnt *client) Restore(containerID string, _ StdioCallback, unusedOnWindows ...CreateOption) error {
560
-	// TODO Windows: Implement this. For now, just tell the backend the container exited.
561 560
 	logrus.Debugf("libcontainerd: Restore(%s)", containerID)
561
+
562
+	// TODO Windows: On RS1, a re-attach isn't possible.
563
+	// However, there is a scenario in which there is an issue.
564
+	// Consider a background container. The daemon dies unexpectedly.
565
+	// HCS will still have the compute service alive and running.
566
+	// For consistence, we call in to shoot it regardless if HCS knows about it
567
+	// We explicitly just log a warning if the terminate fails.
568
+	// Then we tell the backend the container exited.
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
+			}
574
+		}
575
+	}
562 576
 	return clnt.backend.StateChanged(containerID, StateInfo{
563 577
 		CommonStateInfo: CommonStateInfo{
564 578
 			State:    StateExit,