From 962ba636e5d1279fc4da6e1e8eca876eb98ae9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Wed, 15 Jan 2025 15:32:05 -0300 Subject: [PATCH] Do not warn about lease refreshes on destroyed machines (#4167) --- internal/machine/leasable_machine.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/internal/machine/leasable_machine.go b/internal/machine/leasable_machine.go index dd5d495ec9..ac5d1f6095 100644 --- a/internal/machine/leasable_machine.go +++ b/internal/machine/leasable_machine.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strings" "sync" "time" @@ -498,23 +499,25 @@ func (lm *leasableMachine) StartBackgroundLeaseRefresh(ctx context.Context, leas } func (lm *leasableMachine) refreshLeaseUntilCanceled(ctx context.Context, duration time.Duration, delayBetween time.Duration) { - var ( - err error - b = &backoff.Backoff{ - Min: delayBetween - 20*time.Millisecond, - Max: delayBetween + 20*time.Millisecond, - Jitter: true, - } - ) + b := &backoff.Backoff{ + Min: delayBetween - 20*time.Millisecond, + Max: delayBetween + 20*time.Millisecond, + Jitter: true, + } + for { - err = lm.RefreshLease(ctx, duration) - switch { + time.Sleep(b.Duration()) + switch err := lm.RefreshLease(ctx, duration); { + case err == nil: + // good times case errors.Is(err, context.Canceled): return - case err != nil: + case strings.Contains(err.Error(), "machine not found"): + // machine is gone, no need to refresh its lease + return + default: terminal.Warnf("error refreshing lease for machine %s: %v\n", lm.machine.ID, err) } - time.Sleep(b.Duration()) } }