pub struct RetryPolicy {
pub max_reconnect_attempts: u32,
pub initial_backoff_ms: u64,
pub max_backoff_ms: u64,
pub backoff_multiplier: f64,
}Expand description
Backoff knobs applied to reconnect attempts.
Backoff progression for attempt n (1-indexed) is:
min(initial_backoff_ms * backoff_multiplier.powi(n - 1), max_backoff_ms)Examples (defaults):
attempt 1: 500 ms
attempt 2: 1000 ms
attempt 3: 2000 ms
attempt 4: 4000 ms
attempt 5: 8000 ms
attempt 6: 16000 ms (would be next, but capped by attempts=5)Fields§
§max_reconnect_attempts: u32Maximum number of reconnection attempts after a connection drop or
heartbeat miss. 0 disables reconnection entirely (the first connect
failure surfaces). Default 5.
initial_backoff_ms: u64Delay before the first reconnect attempt, in milliseconds.
Default 500.
max_backoff_ms: u64Upper bound for any single backoff delay, in milliseconds. Must be
>= initial_backoff_ms. Default 30_000 (30 seconds — matches the
server-side grace window so a single backoff never exceeds the window
itself).
backoff_multiplier: f64Exponential factor applied between attempts. 2.0 doubles the delay
each attempt. Must be >= 1.0; 1.0 produces constant backoff.
Default 2.0.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(
max_reconnect_attempts: u32,
initial_backoff_ms: u64,
max_backoff_ms: u64,
backoff_multiplier: f64,
) -> Result<Self, Error>
pub fn new( max_reconnect_attempts: u32, initial_backoff_ms: u64, max_backoff_ms: u64, backoff_multiplier: f64, ) -> Result<Self, Error>
Construct a validated RetryPolicy.
Returns Error::Protocol if any knob is out of range. Mirrors the
Python SDK’s __post_init__ validation so an invalid policy fails
loudly at construction rather than producing surprising backoff.
Sourcepub fn backoff_ms(&self, attempt: u32) -> u64
pub fn backoff_ms(&self, attempt: u32) -> u64
Return the delay (in ms) to wait before the given attempt.
attempt is 1-indexed: attempt = 1 is the first reconnect after a
drop, attempt = 2 the second, etc. An attempt of 0 is clamped to 1
(the first backoff) — the public contract is “give me the delay for
the Nth retry” and there is no zeroth retry.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
impl Default for RetryPolicy
Source§impl PartialEq for RetryPolicy
impl PartialEq for RetryPolicy
Source§fn eq(&self, other: &RetryPolicy) -> bool
fn eq(&self, other: &RetryPolicy) -> bool
self and other values to be equal, and is used by ==.