Blame SOURCES/69518f0bbdb1f11113f46a4d794e09e2f21f5e91.patch

b9462c
From 69518f0bbdb1f11113f46a4d794e09e2f21f5e91 Mon Sep 17 00:00:00 2001
b9462c
From: Ulrich Obergfell <uobergfe@redhat.com>
b9462c
Date: Thu, 10 Oct 2019 11:59:44 +0200
b9462c
Subject: [PATCH] fix error handling in restore() function  -  version 2
b9462c
b9462c
If runtime.Load() returns an error, the restore() function removes the
b9462c
/run/docker/libcontainerd/containerd/CONTAINERID directory recursively.
b9462c
However, this is wrong if the error is not related to the init process
b9462c
of the container.
b9462c
b9462c
This patch introduces the following changes to the runtime.Load() function:
b9462c
b9462c
- runtime.Load() handles errors from readProcessState() autonomously. The
b9462c
  /run/docker/libcontainerd/containerd/CONTAINERID/PROCESSID directory will
b9462c
  be removed recursively, and a warning message will be logged.
b9462c
b9462c
- Errors returned by runtime.Load() are always related to the init process,
b9462c
  so restore() may remove /run/docker/libcontainerd/containerd/CONTAINERID.
b9462c
b9462c
Signed-off-by: Ulrich Obergfell <uobergfe@redhat.com>
b9462c
---
b9462c
 runtime/container.go | 9 ++++++---
b9462c
 1 file changed, 6 insertions(+), 3 deletions(-)
b9462c
b9462c
diff --git a/runtime/container.go b/runtime/container.go
b9462c
index 2e9e663..489e407 100644
b9462c
--- a/runtime/container.go
b9462c
+++ b/runtime/container.go
b9462c
@@ -182,11 +182,14 @@ func Load(root, id, shimName string, timeout time.Duration) (Container, error) {
b9462c
 			continue
b9462c
 		}
b9462c
 		pid := d.Name()
b9462c
-		s, err := readProcessState(filepath.Join(root, id, pid))
b9462c
+		processStateDir := filepath.Join(root, id, pid)
b9462c
+		s, err := readProcessState(processStateDir)
b9462c
 		if err != nil {
b9462c
-			return nil, err
b9462c
+			logrus.WithFields(logrus.Fields{"error": err, "pid": pid}).Warnf("containerd: failed to load exec process,removing state directory.")
b9462c
+			os.RemoveAll(processStateDir)
b9462c
+			continue
b9462c
 		}
b9462c
-		p, err := loadProcess(filepath.Join(root, id, pid), pid, c, s)
b9462c
+		p, err := loadProcess(processStateDir, pid, c, s)
b9462c
 		if err != nil {
b9462c
 			logrus.WithField("id", id).WithField("pid", pid).Debugf("containerd: error loading process %s", err)
b9462c
 			continue