From 78cb1e28cbc2a7ef246178edc742ecf61d5962b1 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 12 Aug 2024 11:39:24 +0200 Subject: [PATCH] libpod: do not save expected stop errors in ctr state If we try to stop a contianer that is not running or paused we get an ErrCtrStateInvalid or ErrCtrStopped error. As podman stop is idempotent this is not a user visable error at all so we should also never log it in the container state. Signed-off-by: Paul Holzinger --- libpod/container_api.go | 6 +++++- test/e2e/inspect_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libpod/container_api.go b/libpod/container_api.go index a6a15d3d91..300fe5ca20 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -263,7 +263,11 @@ func (c *Container) StopWithTimeout(timeout uint) (finalErr error) { // defer's are executed LIFO so we are locked here // as long as we call this after the defer unlock() defer func() { - if finalErr != nil { + // The podman stop command is idempotent while the internal function here is not. + // As such we do not want to log these errors in the state because they are not + // actually user visible errors. + if finalErr != nil && !errors.Is(finalErr, define.ErrCtrStopped) && + !errors.Is(finalErr, define.ErrCtrStateInvalid) { if err := saveContainerError(c, finalErr); err != nil { logrus.Debug(err) } diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 202ca036ae..72b3c8b5cc 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -583,6 +583,15 @@ var _ = Describe("Podman inspect", func() { Expect(session).Should(ExitCleanly()) Expect(session.OutputToString()).To(BeEmpty()) + // Stopping the container should be a NOP and not log an error in the state here. + session = podmanTest.Podman([]string{"container", "stop", cid}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + session = podmanTest.Podman([]string{"container", "inspect", cid, "-f", "{{ .State.Error }}"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToString()).To(BeEmpty(), "state error after stop") + commandNotFound := "OCI runtime attempted to invoke a command that was not found" session = podmanTest.Podman([]string{"start", cid}) session.WaitWithDefaultTimeout()