Blob Blame History Raw
From 69518f0bbdb1f11113f46a4d794e09e2f21f5e91 Mon Sep 17 00:00:00 2001
From: Ulrich Obergfell <uobergfe@redhat.com>
Date: Thu, 10 Oct 2019 11:59:44 +0200
Subject: [PATCH] fix error handling in restore() function  -  version 2

If runtime.Load() returns an error, the restore() function removes the
/run/docker/libcontainerd/containerd/CONTAINERID directory recursively.
However, this is wrong if the error is not related to the init process
of the container.

This patch introduces the following changes to the runtime.Load() function:

- runtime.Load() handles errors from readProcessState() autonomously. The
  /run/docker/libcontainerd/containerd/CONTAINERID/PROCESSID directory will
  be removed recursively, and a warning message will be logged.

- Errors returned by runtime.Load() are always related to the init process,
  so restore() may remove /run/docker/libcontainerd/containerd/CONTAINERID.

Signed-off-by: Ulrich Obergfell <uobergfe@redhat.com>
---
 runtime/container.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/runtime/container.go b/runtime/container.go
index 2e9e663..489e407 100644
--- a/runtime/container.go
+++ b/runtime/container.go
@@ -182,11 +182,14 @@ func Load(root, id, shimName string, timeout time.Duration) (Container, error) {
 			continue
 		}
 		pid := d.Name()
-		s, err := readProcessState(filepath.Join(root, id, pid))
+		processStateDir := filepath.Join(root, id, pid)
+		s, err := readProcessState(processStateDir)
 		if err != nil {
-			return nil, err
+			logrus.WithFields(logrus.Fields{"error": err, "pid": pid}).Warnf("containerd: failed to load exec process,removing state directory.")
+			os.RemoveAll(processStateDir)
+			continue
 		}
-		p, err := loadProcess(filepath.Join(root, id, pid), pid, c, s)
+		p, err := loadProcess(processStateDir, pid, c, s)
 		if err != nil {
 			logrus.WithField("id", id).WithField("pid", pid).Debugf("containerd: error loading process %s", err)
 			continue