From 62c393c11900762920d65080a14e9d966c2c5b40 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Mon, 18 Feb 2019 11:56:10 -0600 Subject: [PATCH] virtcontainers: change container's state to stop asap container is killed by force, container's state MUST change its state to stop immediately to avoid leaving it in a bad state. fixes #1088 Signed-off-by: Julio Montes --- virtcontainers/container.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 30f9a78267..92a1befc7e 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -928,6 +928,13 @@ func (c *Container) stop() error { // get failed if the process hasn't exited. c.sandbox.agent.waitProcess(c, c.id) + // container was killed by force, container MUST change its state + // as soon as possible just in case one of below operations fail leaving + // the containers in a bad state. + if err := c.setContainerState(types.StateStopped); err != nil { + return err + } + if err := c.sandbox.agent.stopContainer(c.sandbox, *c); err != nil { return err } @@ -940,7 +947,7 @@ func (c *Container) stop() error { return err } - return c.setContainerState(types.StateStopped) + return nil } func (c *Container) enter(cmd types.Cmd) (*Process, error) {