pub struct RetryPolicy { /* private fields */ }retry only.Expand description
Retries 429 Too Many Requests, 408 Request Timeout and 5xx responses, and failures to connect.
- It waits as long as the server asks, with
retry-after-ms(milliseconds) orRetry-After(seconds or an HTTP date), up toRetryPolicy::max_retry_after(60 s by default). The wait is read once into a deadline, counted from when the response arrived, and the policy sleeps until it: time spent in between (reading a429body forRetryLayer::permanent_429) is not added. A server that asks for longer thanmax_retry_aftergets its response returned at once: waiting less than it asked would likely fail again, and waiting an hour is rarely what a caller wants. A date in the past means retry now. - With
RetryPolicy::server_directed_429, a429is retried only when the server says when. - Without those headers it backs off exponentially from
RetryPolicy::base_delay(200 ms), doubling on each retry up toRetryPolicy::max_delay(8 s), with jitter: each delay is picked at random between half and all of it, so that clients that failed together do not retry together.RetryPolicy::jitterturns that off. - It never retries a response marked
Permanent(seeRetryLayer::permanent_429), nor a request whose body is a stream (a streamed file upload), which cannot be sent again.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_retries: usize) -> Self
pub fn new(max_retries: usize) -> Self
A policy that retries at most max_retries times (after the first attempt).
Sourcepub fn base_delay(self, delay: Duration) -> Self
pub fn base_delay(self, delay: Duration) -> Self
The first backoff delay, doubled on each retry (default 200 ms).
Sourcepub fn max_delay(self, delay: Duration) -> Self
pub fn max_delay(self, delay: Duration) -> Self
The longest backoff delay (default 8 s). It does not limit how long a server can ask to wait with
Retry-After: that is RetryPolicy::max_retry_after.
Sourcepub fn max_retry_after(self, delay: Duration) -> Self
pub fn max_retry_after(self, delay: Duration) -> Self
The longest wait a server can ask for with Retry-After or retry-after-ms (default 60 s). A response that
asks for longer is not retried but returned.
Sourcepub fn jitter(self, jitter: bool) -> Self
pub fn jitter(self, jitter: bool) -> Self
Whether each backoff delay is picked at random between half and all of it (default true). The waits a
server asks for are never jittered.
Sourcepub fn server_directed_429(self, server_directed: bool) -> Self
pub fn server_directed_429(self, server_directed: bool) -> Self
Whether a 429 is retried only when the server says when, with Retry-After or retry-after-ms (default
false: every 429 is retried, with backoff when the server does not say when).
Some APIs answer a 429 without advice when waiting will not help (a quota, a request too large for a rate
limit), and with it when it will. 408, 5xx and connect failures are retried either way.
Sourcepub fn max_retries(&self) -> usize
pub fn max_retries(&self) -> usize
The number of retries allowed.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
Three retries.
impl Default for RetryPolicy
Three retries.