From 62cdc387de982feb796af71252a3fe3d504d570c Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 8 Jul 2022 15:17:43 +0200 Subject: podman wait: return 0 if container never ran Make sure to return/exit with 0 when waiting for a container that never ran. Signed-off-by: Valentin Rothberg --- libpod/container_api.go | 4 ++++ libpod/oci_conmon_linux.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/container_api.go b/libpod/container_api.go index dbd5fc1fb..742eb6d3e 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -551,6 +551,10 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration) exitCode, err := c.runtime.state.GetContainerExitCode(id) if err != nil { + if errors.Is(err, define.ErrNoSuchExitCode) && c.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated) { + // The container never ran. + return true, 0, nil + } return true, -1, err } diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 0cdfe90e9..121e750f4 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -303,7 +303,7 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error { ctr.state.ExitCode = -1 ctr.state.FinishedTime = time.Now() ctr.state.State = define.ContainerStateExited - return nil + return ctr.runtime.state.AddContainerExitCode(ctr.ID(), ctr.state.ExitCode) } return fmt.Errorf("error getting container %s state. stderr/out: %s: %w", ctr.ID(), out, err) } -- cgit v1.2.3-54-g00ecf From 3bb4cf8ee2ca4d2b5fcd16da95a6ebd60b9ed18b Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 8 Jul 2022 15:36:02 +0200 Subject: libpod: read exit code when cleaning up the runtime While for some call paths we may be doing this redundantly we need to make sure the exit code is always read at this point. [NO NEW TESTS NEEDED] as I do not manage to reproduce the issue which is very likely caused by a code path not writing the exit code when running concurrently. Fixes: #14859 Signed-off-by: Valentin Rothberg --- libpod/container_internal.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libpod') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 560b4a1c1..6a98466c2 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1104,6 +1104,12 @@ func (c *Container) cleanupRuntime(ctx context.Context) error { return nil } + // We may be doing this redundantly for some call paths but we need to + // make sure the exit code is being read at this point. + if err := c.checkExitFile(); err != nil { + return err + } + // If necessary, delete attach and ctl files if err := c.removeConmonFiles(); err != nil { return err -- cgit v1.2.3-54-g00ecf