Skip to content

fix(buildRequest): handle RPC code 429 in shouldRetry for batch mode#4440

Open
luanxu-dev wants to merge 2 commits intowevm:mainfrom
luanxu-dev:fix/batch-retry-429
Open

fix(buildRequest): handle RPC code 429 in shouldRetry for batch mode#4440
luanxu-dev wants to merge 2 commits intowevm:mainfrom
luanxu-dev:fix/batch-retry-429

Conversation

@luanxu-dev
Copy link
Copy Markdown

Summary

Fixes #3680

Root cause

shouldRetry in src/utils/buildRequest.ts has two branches:

  1. error.code branch — handles standard JSON-RPC error codes (-1, -32005, -32603). Any other numeric code hits return falseno retry.
  2. HttpRequestError branch — handles HTTP status codes including 429.

Some providers (most notably Alchemy in batch mode) respond with HTTP 200 and a JSON-RPC body of { code: 429 } rather than a real HTTP 429 response. Because the error arrives with code: 429 (a number), it matches branch 1 — but 429 is not in the recognised set, so shouldRetry returns false and retryCount is silently ignored.

Fix

Add an explicit check for error.code === 429 in the code branch, before the return false fallthrough:

// Too Many Requests — some providers (e.g. Alchemy in batch mode) return
// HTTP 200 with a JSON-RPC body of `{ code: 429 }` instead of an HTTP 429,
// so we need to handle this code in addition to the HTTP status check below.
if (error.code === 429) return true

Test

Added a unit test that creates a plain Error with code: 429 (no HTTP status) and asserts shouldRetry returns true.

Notes

  • The existing HTTP 429 path (HttpRequestError with status === 429) is unchanged.
  • This does not affect behaviour for any currently-handled error code.

luanxu-dev and others added 2 commits April 2, 2026 08:01
Some providers (e.g. Alchemy in batch mode) return HTTP 200 with a
JSON-RPC body containing `{ code: 429 }` instead of a real HTTP 429
status. The existing shouldRetry code-path only recognised standard
RPC error codes (-1, -32005, -32603) and fell through to `return false`,
silently disabling retries.

Add an explicit `error.code === 429` check so retryCount is honoured.

Fixes: wevm#3680

Co-Authored-By: Paperclip <noreply@paperclip.ing>
…-limit)

Covers the case where a provider returns HTTP 200 with JSON body
`{ code: 429 }` (Alchemy batch mode) — shouldRetry must return true.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

@luanxu-dev is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 2, 2026

⚠️ No Changeset found

Latest commit: 528af62

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: retryCount doesn't work with batch requests for RPC-level errors

1 participant