Skip to content

Commit

Permalink
rpc-client: retry execution timeout errors (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash authored Nov 1, 2024
1 parent df25b72 commit 0fdeb38
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/evm-processor",
"comment": "allow to configure number of rpc connection errors retry attempts",
"type": "minor"
}
],
"packageName": "@subsquid/evm-processor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/rpc-client",
"comment": "make `exectution timeout` error retryable",
"type": "minor"
}
],
"packageName": "@subsquid/rpc-client"
}
8 changes: 7 additions & 1 deletion evm/evm-processor/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export interface RpcEndpointSettings {
* Request timeout in `ms`
*/
requestTimeout?: number
/**
* Maximum number of retry attempts.
*
* By default, retries all "retryable" errors indefinitely.
*/
retryAttempts?: number
/**
* Maximum number of requests in a single batch call
*/
Expand Down Expand Up @@ -442,7 +448,7 @@ export class EvmBatchProcessor<F extends FieldSelection = {}> {
requestTimeout: this.rpcEndpoint.requestTimeout ?? 30_000,
capacity: this.rpcEndpoint.capacity ?? 10,
rateLimit: this.rpcEndpoint.rateLimit,
retryAttempts: Number.MAX_SAFE_INTEGER,
retryAttempts: this.rpcEndpoint.retryAttempts ?? Number.MAX_SAFE_INTEGER,
log: this.getLogger().child('rpc', {rpcUrl: this.rpcEndpoint.url})
})
this.getPrometheusServer().addChainRpcMetrics(() => client.getMetrics())
Expand Down
6 changes: 6 additions & 0 deletions util/rpc-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export class RpcClient {
isConnectionError(err: Error): boolean {
if (err instanceof RetryError) return true
if (isRateLimitError(err)) return true
if (isExecutionTimeoutError(err)) return true
if (err instanceof RpcConnectionError) return true
if (isHttpConnectionError(err)) return true
if (err instanceof HttpTimeoutError) return true
Expand Down Expand Up @@ -570,6 +571,11 @@ function isRateLimitError(err: unknown): boolean {
}


function isExecutionTimeoutError(err: unknown): boolean {
return err instanceof RpcError && /execution timeout/i.test(err.message)
}


function removeItem<T>(arr: T[], item: T): void {
let index = arr.indexOf(item)
if (index < 0) return
Expand Down

0 comments on commit 0fdeb38

Please sign in to comment.