Documentation
¶
Overview ¶
Package backoff computes retry delays.
It exists as its own package so that the delay arithmetic — the part that is easy to get subtly wrong and easy to test in isolation — is not tangled up with the LDAP error classification that decides whether to retry at all.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Policy ¶
type Policy struct {
// Base is the delay before the first retry. Subsequent delays grow
// from it by Multiplier.
Base time.Duration
// Max caps a single delay, however many attempts have failed.
Max time.Duration
// Multiplier is the growth factor between attempts. Values below 1
// are treated as 1, which turns the policy into a constant delay.
Multiplier float64
}
Policy describes a capped exponential backoff with full jitter.
Full jitter, rather than the exponential delay itself or the delay plus a small random nudge, is what actually decorrelates a fleet of clients that all lost their directory at the same instant: every waiter picks uniformly from [0, delay), so the retries spread across the window instead of arriving together at the end of it.
func (Policy) Delay ¶
Delay returns how long to wait before attempt number n, where n counts from 1 for the first retry. A non-positive n returns zero.
The caller is expected to sample once per retry and to select on its context while waiting; Delay does no waiting of its own and touches no clock, which is why it is trivially testable.