Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vc: stop container should change container state at last
Browse files Browse the repository at this point in the history
Otherwise if we fail to stop it, container state is set as StateStopped.
And future force stop will just be ignored. Then when we force delete
the container, we are deleting it without actually cleaning up container
resources especially the host shared mounts, which would be removed by
agent cleanup code and we endup removing container volume contents
unexpectedly.

Fixes: #2345
Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Dec 11, 2019
1 parent e3115e3 commit 743309c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,6 @@ func (c *Container) stop(force bool) 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
}

defer func() {
// Save device and drive data.
// TODO: can we merge this saving with setContainerState()?
Expand Down Expand Up @@ -1133,6 +1126,13 @@ func (c *Container) stop(force bool) error {
return err
}

// 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
}

return nil
}

Expand Down

0 comments on commit 743309c

Please sign in to comment.