Documentation
¶
Overview ¶
Package receivewait paces a consumer's receive loop after a failed receive.
A broker's own long-polling paces the loop while it is working; a receive that fails returns immediately, so a persistent failure — expired credentials, a deleted queue, a partitioned broker — spins the loop as fast as the CPU and the broker's API allow, burning a core and the request quota for as long as it lasts. Every consumer therefore needs a wait here, and the two that had one disagreed about what it should be: SQS grew from 100ms to 30s, Kafka paused a flat 250ms forever.
Neither jittered, which is the part that matters at fleet scale. A broker that goes away takes every consumer with it at the same instant, and un-jittered backoff has them all come back at the same instant too — turning a recovering broker's first moment back into the same thundering herd that is still arriving when it falls over again.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
Backoff is one consumer's receive-loop pacing. It is not safe for concurrent use; a consumer's loop is a single goroutine.
The zero value is not usable — build one with New, which resolves the clock.
func New ¶
New builds a Backoff against c, which may be nil for the wall clock.
rand may be nil for the default source; it is a parameter so a test can pin the schedule rather than assert on a range.
func (*Backoff) Reset ¶
func (b *Backoff) Reset()
Reset returns the wait to its floor, and is called after every receive that succeeds — so a queue that fails once an hour never accumulates its way to the ceiling.
func (*Backoff) Wait ¶
Wait sleeps out the backoff for the failure that just happened, growing it, and reports a context that went away underneath it.
The jitter is retry.Equal rather than retry.Full because this caller sleeps in place: half the schedule stays under every wait, so a loop that has backed off to thirty seconds cannot draw a near-zero one and become hot again.