Skip to content

Commit c3e07ce

Browse files
fix: Limit 429 retries (#602)
1 parent 7a109b9 commit c3e07ce

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## Unreleased
1010

11+
* Limited the number of HTTP 429 retries. Users receiving this error should configure `with_max_concurrent_requests`.
1112
* Added `Envelope::encode_bytes` and `Query/UpdateBuilder::into_envelope` for external signing workflows.
1213
* Added `AgentBuilder::with_arc_http_middleware` for `Transport`-like functionality at the level of HTTP requests.
1314
* Add support for dynamic routing based on boundary node discovery. This is an internal feature for now, with a feature flag `_internal_dynamic-routing`.

ic-agent/src/agent/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,17 +1926,23 @@ impl HttpService for Retry429Logic {
19261926
async fn call<'a>(
19271927
&'a self,
19281928
req: &'a (dyn Fn() -> Result<Request, AgentError> + Send + Sync),
1929-
_max_retries: usize,
1929+
_max_tcp_retries: usize,
19301930
) -> Result<Response, AgentError> {
1931+
let mut retries = 0;
19311932
loop {
19321933
#[cfg(not(target_family = "wasm"))]
1933-
let resp = self.client.call(req, _max_retries).await?;
1934+
let resp = self.client.call(req, _max_tcp_retries).await?;
19341935
// Client inconveniently does not implement Service on wasm
19351936
#[cfg(target_family = "wasm")]
19361937
let resp = self.client.execute(req()?).await?;
19371938
if resp.status() == StatusCode::TOO_MANY_REQUESTS {
1938-
crate::util::sleep(Duration::from_millis(250)).await;
1939-
continue;
1939+
if retries == 6 {
1940+
break Ok(resp);
1941+
} else {
1942+
retries += 1;
1943+
crate::util::sleep(Duration::from_millis(250)).await;
1944+
continue;
1945+
}
19401946
} else {
19411947
break Ok(resp);
19421948
}

0 commit comments

Comments
 (0)