Skip to content

Commit

Permalink
libpod: wait another interval for healthcheck
Browse files Browse the repository at this point in the history
wait for another interval when the container transitioned to "stopped"
to give more time to the healthcheck status to change.

Closes: containers#22760

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed May 22, 2024
1 parent fa05adb commit e166f6b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
wg.Add(1)
go func() {
defer wg.Done()

stoppedCount := 0
for {
if len(wantedStates) > 0 {
state, err := c.State()
Expand All @@ -784,10 +784,17 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
// 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
if stoppedCount > 0 {
stoppedCount++
} else {
state, err := c.State()
if err != nil {
trySend(-1, err)
return
}
if state != define.ContainerStateCreated && state != define.ContainerStateRunning && state != define.ContainerStatePaused {
stoppedCount++
}
}
status, err := c.HealthCheckStatus()
if err != nil {
Expand All @@ -798,7 +805,9 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
trySend(-1, nil)
return
}
if state != define.ContainerStateCreated && state != define.ContainerStateRunning && state != define.ContainerStatePaused {
// wait for another waitTimeout interval to give the health check process some time
// to record the healthy status.
if stoppedCount > 1 {
trySend(-1, define.ErrCtrStopped)
return
}
Expand Down

0 comments on commit e166f6b

Please sign in to comment.