Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,61 @@ func (c *Container) waitForHealthy(ctx context.Context) error {
defer c.lock.Lock()
}

healthStartPeriod := c.config.HealthCheckConfig.StartPeriod
needsExtension := healthStartPeriod > 0
var extendedTotal time.Duration
extension := 30 * time.Second
timerFreq := 25 * time.Second

if needsExtension {
timer := time.NewTicker(timerFreq)
extendCtx, cancel := context.WithCancel(ctx)
defer cancel()
defer timer.Stop()

// compute next chunk
sendExtend := func() {
remaining := healthStartPeriod - extendedTotal
if remaining <= 0 {
return
}

step := extension
if step > remaining {
step = remaining
}

// Build the EXTEND message
msg := fmt.Sprintf("EXTEND_TIMEOUT_USEC=%d", step.Microseconds())
if err := notifyproxy.SendMessage(c.config.SdNotifySocket, msg); err != nil {
logrus.Errorf("EXTEND_TIMEOUT_USEC failed in health-wait: %w", err)
} else {
logrus.Debugf("Extended startup by %v (total %v / %v)",
step, extendedTotal+step, healthStartPeriod)
}

extendedTotal += step
}

// First extension immediately
sendExtend()

// Background periodic extension loop
go func() {
for {
select {
case <-extendCtx.Done():
return
case <-timer.C:
if extendedTotal >= healthStartPeriod {
return
}
sendExtend()
}
}
}()
}

if _, err := c.WaitForConditionWithInterval(ctx, DefaultWaitInterval, define.HealthCheckHealthy); err != nil {
if errors.Is(err, define.ErrNoSuchCtr) {
return nil
Expand Down