libpod: correctly guard StartedTime access in runHealthCheck

The state must be synced from the db when we are locked otherwise it
contains incorrect values.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2026-06-23 18:59:30 +02:00
parent cd6807c7c0
commit d9bab9caac

View File

@@ -59,8 +59,17 @@ func (c *Container) runHealthCheck(ctx context.Context, isStartup bool) (define.
timeStart := time.Now()
if c.HealthCheckConfig().StartPeriod > 0 {
// state must be synced from DB
c.lock.Lock()
if err := c.syncContainer(); err != nil {
c.lock.Unlock()
return define.HealthCheckInternalError, "", err
}
// there is a start-period we need to honor; we add startPeriod to container start time
startPeriodTime := c.state.StartedTime.Add(c.HealthCheckConfig().StartPeriod)
c.lock.Unlock()
// Do not stay locked here, in healthCheckExec it will lock again.
if timeStart.Before(startPeriodTime) {
// we are still in the start period, flip the inStartPeriod bool
inStartPeriod = true