From 746f5db66f51174b7c8226951c889825e711f1ca Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Wed, 6 Aug 2025 14:55:48 +0300 Subject: [PATCH] Add a maximum to the exponential backoff wait duration --- crates/common/Cargo.toml | 2 +- crates/common/src/futures/poll.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index aa9ad4c..516b1be 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -11,4 +11,4 @@ rust-version.workspace = true [dependencies] anyhow = { workspace = true } semver = { workspace = true } -tokio = { workspace = true } +tokio = { workspace = true, default-features = false, features = ["time"] } diff --git a/crates/common/src/futures/poll.rs b/crates/common/src/futures/poll.rs index 284f4b6..2697541 100644 --- a/crates/common/src/futures/poll.rs +++ b/crates/common/src/futures/poll.rs @@ -3,6 +3,8 @@ use std::time::Duration; use anyhow::{Result, anyhow}; +const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60); + /// A function that polls for a fallible future for some period of time and errors if it fails to /// get a result after polling. /// @@ -42,6 +44,7 @@ where PollingWaitBehavior::Constant(duration) => duration, PollingWaitBehavior::ExponentialBackoff => { Duration::from_secs(2u64.pow(retries)) + .min(EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION) } }; let next_wait_duration =