From 35375e0af835568258e859ce554811d8c4e7c77f Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 14 May 2024 22:49:07 +0200 Subject: [PATCH] container_api: do not wait for healtchecks if stopped do not wait for the healthcheck status to change if the container is stopped. Signed-off-by: Giuseppe Scrivano --- libpod/container_api.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libpod/container_api.go b/libpod/container_api.go index 4168b1d7cc..52b7e145de 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -781,6 +781,14 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou } } if len(wantedHealthStates) > 0 { + // even if we are interested only in the health check + // check that the container is still running to avoid + // waiting until the timeout expires. + state, err := c.State() + if err != nil { + trySend(-1, err) + return + } status, err := c.HealthCheckStatus() if err != nil { trySend(-1, err) @@ -790,6 +798,10 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou trySend(-1, nil) return } + if state != define.ContainerStateCreated && state != define.ContainerStateRunning && state != define.ContainerStatePaused { + trySend(-1, define.ErrCtrStopped) + return + } } select { case <-ctx.Done():