Skip to content

Commit

Permalink
Retry on rpc timeout response (#518)
Browse files Browse the repository at this point in the history
* retry on rpc timeout response

* run fmt
  • Loading branch information
gianfra-t authored May 6, 2024
1 parent 9aafee4 commit ea66a30
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions clients/runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ impl Error {
&format!("{:?}", SecurityPalletError::ParachainNotRunning),
)
}

pub fn is_timeout_error(&self) -> bool {
match self {
Error::SubxtRuntimeError(SubxtError::Rpc(RpcError::ClientError(e))) =>
match e.downcast_ref::<JsonRpseeError>() {
Some(e) => matches!(e, JsonRpseeError::RequestTimeout),
None => {
log::error!(
"Failed to downcast RPC error; this is a bug please file an issue"
);
false
},
},
_ => false,
}
}
}

impl RecoverableError {
Expand Down
2 changes: 2 additions & 0 deletions clients/runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ impl SpacewalkParachain {
} else if err.is_block_hash_not_found_error() {
log::info!("Re-sending transaction after apparent fork");
Err(RetryPolicy::Skip(Error::BlockHashNotFound))
} else if err.is_timeout_error() {
Err(RetryPolicy::Skip(Error::Timeout))
} else {
Err(RetryPolicy::Throw(err))
}
Expand Down
4 changes: 3 additions & 1 deletion clients/vault/src/oracle/storage/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ pub trait ArchiveStorage {
fn remove_file(&self, target_slot: Slot) {
let (_, file) = self.get_url_and_file_name(target_slot);
if let Err(e) = fs::remove_file(&file) {
tracing::warn!("remove_file(): failed to remove file {file} for slot {target_slot}: {e:?}");
tracing::warn!(
"remove_file(): failed to remove file {file} for slot {target_slot}: {e:?}"
);
}
}

Expand Down
2 changes: 2 additions & 0 deletions clients/vault/src/requests/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ impl Request {
Err(RetryPolicy::Throw(err))
} else if err.is_block_hash_not_found_error() {
Err(RetryPolicy::Skip(EnrichedError::BlockHashNotFound))
} else if err.is_timeout_error() {
Err(RetryPolicy::Skip(EnrichedError::Timeout))
} else {
Err(RetryPolicy::Throw(err))
}
Expand Down

0 comments on commit ea66a30

Please sign in to comment.