Module retry
http and std only.Expand description
Middleware for retrying “failed” requests.
Every attempt runs on its own fork of the caller’s
request Extensions: an attempt reads everything the
caller inserted, while what it (or any inner layer) inserts stays isolated from the caller and
from every other attempt. A failed attempt therefore cannot steer the next one by inserting.
Isolation is structural, not deep: an inherited value is shared by handle, so interior mutation through it stays visible to the caller and to every other attempt — which is exactly how a caller-owned counter or budget is meant to work. Only the entries an attempt inserts itself are private to it.
This holds whether or not the request turns out to be retryable: what the Policy decides
about retrying has no bearing on who owns the request’s extensions.
The Policy itself is the one exception to that isolation: it is handed a request backed by
the caller’s own store, so metadata it records there (a retry count, an exhaustion marker)
reaches the next attempt and stays visible to the caller. Only the inner service’s inserts are
private to an attempt.
§Layer placement
Place RetryLayer as early — as far outward — in the stack as your use case allows, in front
of everything whose work depends on the request: route or proxy selection, DNS overwrites,
per-target limits. Such a layer placed outside runs exactly once, and every attempt then
reuses its verdict — retrying through the very proxy or address that just failed. Placed
inside, it is consulted per attempt.
One counterweight: retrying requires a replayable body, so this middleware buffers the request
body in full (RetryBody) and every layer inside it sees that buffered body instead of the
original stream.
follow_redirect follows the same rules for redirect hops. Keep
that middleware outside this one, so a retry replays one hop instead of the entire chain.
Modules§
Structs§
- Managed
Policy - A managed retry
Policy, which allows for an easier interface to configure retrying requests. - Retry
- Configure retrying requests of “failed” responses.
- Retry
Body - A body that can be clone and used for requests that have to be rertried.
- Retry
Error - Error type for
Retry - Retry
Layer - Retry requests based on a policy
Enums§
- Policy
Result - The full result of a limit policy.
Traits§
- Policy
- A “retry policy” to classify if a request should be retried.