Skip to content

Commit

Permalink
core/expiration: Add backoff jitter to the expiration retries (#10937)
Browse files Browse the repository at this point in the history
  • Loading branch information
briankassouf authored Feb 19, 2021
1 parent d04b88d commit 88d8d18
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vault/expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -218,8 +219,7 @@ func (r *revocationJob) OnFailure(err error) {
return
}

// TODO vault 1.8 we added an exponential backoff library, check to see if it would be useful here
pending.timer.Reset((1 << pending.revokesAttempted) * revokeRetryBase)
pending.timer.Reset(revokeExponentialBackoff(pending.revokesAttempted))
r.m.pending.Store(r.leaseID, pending)
}

Expand Down Expand Up @@ -248,6 +248,15 @@ func expireLeaseStrategyFairsharing(ctx context.Context, m *ExpirationManager, l
m.jobManager.AddJob(job, mountAccessor)
}

func revokeExponentialBackoff(attempt uint8) time.Duration {
exp := (1 << attempt) * revokeRetryBase
randomDelta := 0.5 * float64(exp)

// Allow backoff time to be a random value between exp +/- (0.5*exp)
backoffTime := (float64(exp) - randomDelta) + (rand.Float64() * (2 * randomDelta))
return time.Duration(backoffTime)
}

// revokeIDFunc is invoked when a given ID is expired
func expireLeaseStrategyRevoke(ctx context.Context, m *ExpirationManager, leaseID string, ns *namespace.Namespace) {
for attempt := uint(0); attempt < maxRevokeAttempts; attempt++ {
Expand Down

0 comments on commit 88d8d18

Please sign in to comment.