From 251677aee82414fd9c88b89a0b5e99a64bad3cd6 Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Mon, 5 Feb 2024 20:07:06 -0400 Subject: [PATCH] fix(foundry-common): Do not retry custom errors --- crates/common/src/provider/retry.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/common/src/provider/retry.rs b/crates/common/src/provider/retry.rs index bf1d0c31cb07..39248a8a38e9 100644 --- a/crates/common/src/provider/retry.rs +++ b/crates/common/src/provider/retry.rs @@ -1,6 +1,6 @@ //! An utility trait for retrying requests based on the error type. See [TransportError]. use alloy_json_rpc::ErrorPayload; -use alloy_transport::TransportError; +use alloy_transport::{TransportError, TransportErrorKind}; use serde::Deserialize; /// [RetryPolicy] defines logic for which [JsonRpcClient::Error] instances should @@ -24,7 +24,9 @@ pub struct RateLimitRetryPolicy; impl RetryPolicy for RateLimitRetryPolicy { fn should_retry(&self, error: &TransportError) -> bool { match error { - TransportError::Transport(_) => true, + // There was a transport-level error. This is either a non-retryable error, + // or a server error that should be retried. + TransportError::Transport(err) => should_retry_transport_level_error(err), // The transport could not serialize the error itself. The request was malformed from // the start. TransportError::SerError(_) => false, @@ -65,6 +67,18 @@ impl RetryPolicy for RateLimitRetryPolicy { } } +/// Analyzes the [TransportErrorKind] and decides if the request should be retried based on the +/// variant. +fn should_retry_transport_level_error(error: &TransportErrorKind) -> bool { + match error { + // Missing batch response errors can be retried. + TransportErrorKind::MissingBatchResponse(_) => true, + // If the backend is gone, or there's a completely custom error, we should assume it's not + // retryable. + _ => false, + } +} + /// Analyzes the [ErrorPayload] and decides if the request should be retried based on the /// error code or the message. fn should_retry_json_rpc_error(error: &ErrorPayload) -> bool {