summaryrefslogtreecommitdiff
path: root/libpod/runtime_ctr.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2020-05-14 11:58:02 -0400
committerMatthew Heon <mheon@redhat.com>2020-05-14 11:58:02 -0400
commit892d81685c9fc213b0e9d444f953577ebb89593b (patch)
treec7b06b49d67ad89a41b28f705e99269f2ede0a54 /libpod/runtime_ctr.go
parent83a1e2e5d22761ad62de8e202938bbdb4896f236 (diff)
downloadpodman-892d81685c9fc213b0e9d444f953577ebb89593b.tar.gz
podman-892d81685c9fc213b0e9d444f953577ebb89593b.tar.bz2
podman-892d81685c9fc213b0e9d444f953577ebb89593b.zip
Ensure that cleanup runs before we set Removing state
Cleaning up the OCI runtime is not allowed in the Removing state. To ensure it is actually cleaned up, when calling cleanup() as part of removing a container, do so before we set the Removing state, so we can successfully remove. Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r--libpod/runtime_ctr.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 1d880531e..c670822a0 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -488,20 +488,25 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
}
}
+ var cleanupErr error
+
+ // Clean up network namespace, cgroups, mounts.
+ // Do this before we set ContainerStateRemoving, to ensure that we can
+ // actually remove from the OCI runtime.
+ if err := c.cleanup(ctx); err != nil {
+ cleanupErr = errors.Wrapf(err, "error cleaning up container %s", c.ID())
+ }
+
// Set ContainerStateRemoving
c.state.State = define.ContainerStateRemoving
if err := c.save(); err != nil {
+ if cleanupErr != nil {
+ logrus.Errorf(err.Error())
+ }
return errors.Wrapf(err, "unable to set container %s removing state in database", c.ID())
}
- var cleanupErr error
-
- // Clean up network namespace, cgroups, mounts
- if err := c.cleanup(ctx); err != nil {
- cleanupErr = errors.Wrapf(err, "error cleaning up container %s", c.ID())
- }
-
// Stop the container's storage
if err := c.teardownStorage(); err != nil {
if cleanupErr == nil {