Skip to content

Commit

Permalink
Do not warn about lease refreshes on destroyed machines (#4167)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra authored Jan 15, 2025
1 parent 15a12e6 commit 962ba63
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions internal/machine/leasable_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 962ba63

Please sign in to comment.