Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retry infura's header not found #1706

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ethers-providers/src/transports/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ where

/// Implements [RetryPolicy] that will retry requests that errored with
/// status code 429 i.e. TOO_MANY_REQUESTS
///
/// Infura often fails with a `"header not found"` rpc error which is apparently linked to load
/// balancing, which are retried as well.
#[derive(Debug, Default)]
pub struct HttpRateLimitRetryPolicy;

Expand All @@ -336,8 +339,17 @@ impl RetryPolicy<ClientError> for HttpRateLimitRetryPolicy {
ClientError::ReqwestError(err) => {
err.status() == Some(http::StatusCode::TOO_MANY_REQUESTS)
}
// alchemy throws it this way
ClientError::JsonRpcError(JsonRpcError { code, message: _, data: _ }) => *code == 429,
ClientError::JsonRpcError(JsonRpcError { code, message, data: _ }) => {
// alchemy throws it this way
if *code == 429 {
return true
}
// this is commonly thrown by infura and is apparently a load balancer issue, see also <https://github.com/MetaMask/metamask-extension/issues/7234>
if message == "header not found" {
return true
}
false
}
_ => false,
}
}
Expand Down