rm: fix cleanup race

we fire the cleanup process asynchronously so we might race with a
command like: podman run --rm --name foo ... && podman run --rm --name foo

Fix it by ensuring the container is deleted before we exit.  This
will race with the "cleanup" process, but it is fine as one of the two
commands will fail with ErrNoSuchCtr while the other succeeds.

Closes: https://github.com/containers/libpod/issues/2619

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-03-13 12:52:12 +01:00
parent 22fc5a3e57
commit 17b60891b6
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
1 changed files with 4 additions and 0 deletions

View File

@ -166,6 +166,10 @@ func runCmd(c *cliconfig.RunValues) error {
exitCode = int(ecode)
}
if c.IsSet("rm") {
runtime.RemoveContainer(ctx, ctr, false, true)
}
return nil
}