Skip to content

Commit

Permalink
fix(foundry-common): Do not retry custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Feb 6, 2024
1 parent 0688b5a commit 96964b0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/common/src/provider/retry.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 96964b0

Please sign in to comment.