From 9773a76dd422ed8c625ac994f0ffbb5f7c20fc1c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 16 Sep 2022 01:51:57 +0200 Subject: [PATCH] feat: retry infura's header not found (#1706) --- ethers-providers/src/transports/retry.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ethers-providers/src/transports/retry.rs b/ethers-providers/src/transports/retry.rs index 41495e56..a48d9980 100644 --- a/ethers-providers/src/transports/retry.rs +++ b/ethers-providers/src/transports/retry.rs @@ -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; @@ -336,8 +339,17 @@ impl RetryPolicy 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 + if message == "header not found" { + return true + } + false + } _ => false, } }