Skip to content

Commit

Permalink
container_api: do not wait for healtchecks if stopped
Browse files Browse the repository at this point in the history
do not wait for the healthcheck status to change if the container is
stopped.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed May 15, 2024
1 parent b06c58b commit 35375e0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 35375e0

Please sign in to comment.