From 79098d354630db4137d14b324f7d1fc848a49dab Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Tue, 28 Oct 2025 18:50:29 +0100 Subject: [PATCH] feat: Enhance DHCP client timeout and retry logic (#908) --- pkg/nmlite/jetdhcpc/client.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/nmlite/jetdhcpc/client.go b/pkg/nmlite/jetdhcpc/client.go index 155ea249..102d3bee 100644 --- a/pkg/nmlite/jetdhcpc/client.go +++ b/pkg/nmlite/jetdhcpc/client.go @@ -111,6 +111,7 @@ type Client struct { var ( defaultTimerDuration = 1 * time.Second defaultLinkUpTimeout = 30 * time.Second + defaultDHCPTimeout = 5 * time.Second // DHCP request timeout (not link up timeout) maxRenewalAttemptDuration = 2 * time.Hour ) @@ -125,11 +126,11 @@ func NewClient(ctx context.Context, ifaces []string, c *Config, l *zerolog.Logge } if cfg.Timeout == 0 { - cfg.Timeout = defaultLinkUpTimeout + cfg.Timeout = defaultDHCPTimeout } if cfg.Retries == 0 { - cfg.Retries = 3 + cfg.Retries = 4 } return &Client{ @@ -153,9 +154,15 @@ func NewClient(ctx context.Context, ifaces []string, c *Config, l *zerolog.Logge }, nil } -func resetTimer(t *time.Timer, l *zerolog.Logger) { - l.Debug().Dur("delay", defaultTimerDuration).Msg("will retry later") - t.Reset(defaultTimerDuration) +func resetTimer(t *time.Timer, attempt int, l *zerolog.Logger) { + // Exponential backoff: 1s, 2s, 4s, 8s, max 8s + backoffAttempt := attempt + if backoffAttempt > 3 { + backoffAttempt = 3 + } + delay := time.Duration(1<