From c3e07ceecc6456dfccfc5bf7953f008804bb0b4b Mon Sep 17 00:00:00 2001 From: Adam Spofford <93943719+adamspofford-dfinity@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:58:44 -0700 Subject: [PATCH] fix: Limit 429 retries (#602) --- CHANGELOG.md | 1 + ic-agent/src/agent/mod.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdd3341..49cfbaaf 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 0978652f..4150bcbf 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_tcp_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_tcp_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 == 6 { + break Ok(resp); + } else { + retries += 1; + crate::util::sleep(Duration::from_millis(250)).await; + continue; + } } else { break Ok(resp); }