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

fix(foundry-common): Do not retry custom errors #7017

Merged
merged 1 commit into from
Feb 6, 2024
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
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
Loading