diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdd33413..49cfbaafc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +* Limited the number of HTTP 429 retries. Users receiving this error should configure `with_max_concurrent_requests`. * Added `Envelope::encode_bytes` and `Query/UpdateBuilder::into_envelope` for external signing workflows. * Added `AgentBuilder::with_arc_http_middleware` for `Transport`-like functionality at the level of HTTP requests. * Add support for dynamic routing based on boundary node discovery. This is an internal feature for now, with a feature flag `_internal_dynamic-routing`. diff --git a/ic-agent/src/agent/mod.rs b/ic-agent/src/agent/mod.rs index 0978652f0..c57b71ed7 100644 --- a/ic-agent/src/agent/mod.rs +++ b/ic-agent/src/agent/mod.rs @@ -1926,17 +1926,23 @@ impl HttpService for Retry429Logic { async fn call<'a>( &'a self, req: &'a (dyn Fn() -> Result + Send + Sync), - _max_retries: usize, + max_retries: usize, ) -> Result { + let mut retries = 0; loop { #[cfg(not(target_family = "wasm"))] - let resp = self.client.call(req, _max_retries).await?; + let resp = self.client.call(req, max_retries).await?; // Client inconveniently does not implement Service on wasm #[cfg(target_family = "wasm")] let resp = self.client.execute(req()?).await?; if resp.status() == StatusCode::TOO_MANY_REQUESTS { - crate::util::sleep(Duration::from_millis(250)).await; - continue; + if retries == max_retries { + break Ok(resp); + } else { + retries += 1; + crate::util::sleep(Duration::from_millis(250)).await; + continue; + } } else { break Ok(resp); }