feat: retry infura's header not found (#1706)

This commit is contained in:
Matthias Seitz 2022-09-16 01:51:57 +02:00 committed by GitHub
parent 37bd21db16
commit 9773a76dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -327,6 +327,9 @@ where
/// Implements [RetryPolicy] that will retry requests that errored with /// Implements [RetryPolicy] that will retry requests that errored with
/// status code 429 i.e. TOO_MANY_REQUESTS /// 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)] #[derive(Debug, Default)]
pub struct HttpRateLimitRetryPolicy; pub struct HttpRateLimitRetryPolicy;
@ -336,8 +339,17 @@ impl RetryPolicy<ClientError> for HttpRateLimitRetryPolicy {
ClientError::ReqwestError(err) => { ClientError::ReqwestError(err) => {
err.status() == Some(http::StatusCode::TOO_MANY_REQUESTS) err.status() == Some(http::StatusCode::TOO_MANY_REQUESTS)
} }
// alchemy throws it this way ClientError::JsonRpcError(JsonRpcError { code, message, data: _ }) => {
ClientError::JsonRpcError(JsonRpcError { code, message: _, data: _ }) => *code == 429, // 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, _ => false,
} }
} }