summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-01-07 13:13:36 +0100
committerValentin Rothberg <rothberg@redhat.com>2021-01-14 17:45:30 +0100
commitd54478d8eaec9481d482942b87065af36995d39a (patch)
tree6c18acf17797a234b3c3f5e95f6e50b71a5d5b1b /libpod/container_api.go
parentd2503ae99b773db7b9dbdf3abf3be0160ac78399 (diff)
downloadpodman-d54478d8eaec9481d482942b87065af36995d39a.tar.gz
podman-d54478d8eaec9481d482942b87065af36995d39a.tar.bz2
podman-d54478d8eaec9481d482942b87065af36995d39a.zip
container stop: release lock before calling the runtime
Podman defers stopping the container to the runtime, which can take some time. Keeping the lock while waiting for the runtime to complete the stop procedure, prevents other commands from acquiring the lock as shown in #8501. To improve the user experience, release the lock before invoking the runtime, and re-acquire the lock when the runtime is finished. Also introduce an intermediate "stopping" to properly distinguish from "stopped" containers etc. Fixes: #8501 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 2c7dc79c9..12207ed0a 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -210,7 +210,13 @@ func (c *Container) Kill(signal uint) error {
}
// TODO: Is killing a paused container OK?
- if c.state.State != define.ContainerStateRunning {
+ switch c.state.State {
+ case define.ContainerStateRunning, define.ContainerStateStopping:
+ // Note that killing containers in "stopping" state is okay.
+ // In that state, the Podman is waiting for the runtime to
+ // stop the container and if that is taking too long, a user
+ // may have decided to kill the container after all.
+ default:
return errors.Wrapf(define.ErrCtrStateInvalid, "can only kill running containers. %s is in state %s", c.ID(), c.state.State.String())
}
@@ -539,7 +545,7 @@ func (c *Container) Cleanup(ctx context.Context) error {
}
// Check if state is good
- if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated, define.ContainerStateStopped, define.ContainerStateExited) {
+ if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated, define.ContainerStateStopped, define.ContainerStateStopping, define.ContainerStateExited) {
return errors.Wrapf(define.ErrCtrStateInvalid, "container %s is running or paused, refusing to clean up", c.ID())
}