Skip to content
Open
Changes from 1 commit
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
64 changes: 64 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/fs"
"maps"
"net"
"os"
"path/filepath"
"slices"
Expand Down Expand Up @@ -1345,6 +1346,69 @@ 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 c.config.SdNotifySocket != "" && needsExtension {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if c.config.SdNotifySocket is empty?


notifyproxy.SendMessage should already handle that.

socketAddr := &net.UnixAddr{
Name: c.config.SdNotifySocket,
Net: "unixgram",
}
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
if err == nil {
defer conn.Close()

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
}

msg := fmt.Appendf(nil, "EXTEND_TIMEOUT_USEC=%d", step.Microseconds())
if _, err := conn.Write(msg); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can sending messages be simplified using notifyproxy.SendMessage?

logrus.Errorf("EXTEND_TIMEOUT_USEC failed in health-wait: %v", 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