From 76b6c4c1b3fc49671f74a645d89a4852ed057139 Mon Sep 17 00:00:00 2001 From: Grooooot Date: Tue, 17 Mar 2020 10:42:12 +0800 Subject: [PATCH] docker: Delete stale containerd object on start failure containerd has two objects with regard to containers. This is a "container" object which is metadata and a "task" which is manging the actual runtime state. When docker starts a container, it creates both the container metadata and the task at the same time. So when a container exists, docker deletes both of these objects as well. This ensures that if, on start, when we go to create the container metadata object in containerd, if there is an error due to a name conflict taht we go ahead and clean that up and try again. backport from upstream: https://github.com/moby/moby/pull/38364 Signed-off-by: Grooooot --- VERSION-openeuler | 2 +- docker-engine-openeuler.spec | 2 +- ...e-stale-containerd-object-on-start-f.patch | 56 +++++++++++++++++++ series.conf | 1 + 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 patch/0161-docker-Delete-stale-containerd-object-on-start-f.patch diff --git a/VERSION-openeuler b/VERSION-openeuler index 32c6fec..9ce0e89 100644 --- a/VERSION-openeuler +++ b/VERSION-openeuler @@ -1 +1 @@ -18.09.0.100 +18.09.0.102 diff --git a/docker-engine-openeuler.spec b/docker-engine-openeuler.spec index affba47..cb4eaec 100644 --- a/docker-engine-openeuler.spec +++ b/docker-engine-openeuler.spec @@ -1,6 +1,6 @@ Name: docker-engine Version: 18.09.0 -Release: 101 +Release: 102 Summary: The open-source application container engine Group: Tools/Docker diff --git a/patch/0161-docker-Delete-stale-containerd-object-on-start-f.patch b/patch/0161-docker-Delete-stale-containerd-object-on-start-f.patch new file mode 100644 index 0000000..6720c29 --- /dev/null +++ b/patch/0161-docker-Delete-stale-containerd-object-on-start-f.patch @@ -0,0 +1,56 @@ +From 6fe2bd73981651b275e508dd2c4806b20853684b Mon Sep 17 00:00:00 2001 +From: Grooooot +Date: Tue, 17 Mar 2020 10:34:59 +0800 +Subject: [PATCH] docker: Delete stale containerd object on start failure + +containerd has two objects with regard to containers. +This is a "container" object which is metadata and a "task" which is +manging the actual runtime state. + +When docker starts a container, it creates both the container metadata +and the task at the same time. So when a container exists, docker deletes +both of these objects as well. + +This ensures that if, on start, when we go to create the container metadata object +in containerd, if there is an error due to a name conflict taht we go +ahead and clean that up and try again. + +backport from upstream: https://github.com/moby/moby/pull/38364 + +Signed-off-by: Grooooot +--- + components/engine/daemon/start.go | 17 +++++++++++++++-- + 1 file changed, 15 insertions(+), 2 deletions(-) + +diff --git a/components/engine/daemon/start.go b/components/engine/daemon/start.go +index 8ff636b..07bffaa 100644 +--- a/components/engine/daemon/start.go ++++ b/components/engine/daemon/start.go +@@ -185,9 +185,22 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint + return err + } + +- err = daemon.containerd.Create(context.Background(), container.ID, spec, createOptions) ++ ctx := context.TODO() ++ ++ err = daemon.containerd.Create(ctx, container.ID, spec, createOptions) + if err != nil { +- return translateContainerdStartErr(container.Path, container.SetExitCode, err) ++ if errdefs.IsConflict(err) { ++ logrus.WithError(err).WithField("container", container.ID).Error("Container not cleaned up from containerd from previous run") ++ // best effort to clean up old container object ++ daemon.containerd.DeleteTask(ctx, container.ID) ++ if err := daemon.containerd.Delete(ctx, container.ID); err != nil && !errdefs.IsNotFound(err) { ++ logrus.WithError(err).WithField("container", container.ID).Error("Error cleaning up stale containerd container object") ++ } ++ err = daemon.containerd.Create(ctx, container.ID, spec, createOptions) ++ } ++ if err != nil { ++ return translateContainerdStartErr(container.Path, container.SetExitCode, err) ++ } + } + + // TODO(mlaventure): we need to specify checkpoint options here +-- +1.8.3.1 + diff --git a/series.conf b/series.conf index 141c9ce..dc86577 100644 --- a/series.conf +++ b/series.conf @@ -156,3 +156,4 @@ patch/0157-docker-Support-check-manifest-and-layer-s-DiffID-inf.patch patch/0158-docker-support-private-registry.patch patch/0159-docker-extend-timeout-in-cli-testcases.patch patch/0160-docker-create-a-soft-link-from-runtime-default-to-ru.patch +patch/0161-docker-Delete-stale-containerd-object-on-start-f.patch -- Gitee