Add a maximum to the exponential backoff wait duration

This commit is contained in:
Omar Abdulla
2025-08-06 14:55:48 +03:00
parent 1400086794
commit 746f5db66f
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -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"] }
+3
View File
@@ -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 =