Merge pull request #18462 from Luap99/no-cleanup-twice

libpod: do not Cleanup() more than once
This commit is contained in:
OpenShift Merge Robot
2023-05-04 09:55:06 -04:00
committed by GitHub
2 changed files with 11 additions and 0 deletions

View File

@ -765,6 +765,11 @@ func (c *Container) Cleanup(ctx context.Context) error {
return fmt.Errorf("container %s is running or paused, refusing to clean up: %w", c.ID(), define.ErrCtrStateInvalid)
}
// if the container was not created in the oci runtime or was already cleaned up, then do nothing
if c.ensureState(define.ContainerStateConfigured, define.ContainerStateExited) {
return nil
}
// Handle restart policy.
// Returns a bool indicating whether we actually restarted.
// If we did, don't proceed to cleanup - just exit.

View File

@ -126,6 +126,12 @@ var _ = Describe("Podman stop", func() {
finalCtrs.WaitWithDefaultTimeout()
Expect(finalCtrs).Should(Exit(0))
Expect(strings.TrimSpace(finalCtrs.OutputToString())).To(Equal(""))
// make sure we only have one cleanup event for this container
events := podmanTest.Podman([]string{"events", "--since=30s", "--stream=false"})
events.WaitWithDefaultTimeout()
Expect(events).Should(Exit(0))
Expect(strings.Count(events.OutputToString(), "container cleanup")).To(Equal(1), "cleanup event should show up exactly once")
})
It("podman stop all containers -t", func() {