Skip to content

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

Merged
jxom merged 3 commits intowevm:mainfrom
luanxu-dev:fix/batch-retry-429
Apr 5, 2026
Merged

fix(buildRequest): handle RPC code 429 in shouldRetry for batch mode#4440
jxom merged 3 commits intowevm:mainfrom
luanxu-dev:fix/batch-retry-429

Conversation

@luanxu-dev
Copy link
Copy Markdown
Contributor

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

🦋 Changeset detected

Latest commit: 0350a4d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

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

@D2758695161
Copy link
Copy Markdown

Great fix! You will need a .changeset file for this to be released. Add .changeset/fix-429-batch.md:


"viem": patch

Retry on 429 error code in batch requests

My PR #4453 also fixes the same - I can close mine if you incorporate the changeset.

@jxom jxom merged commit 75ae99e into wevm:main Apr 5, 2026
2 of 3 checks passed
@github-actions github-actions bot mentioned this pull request Apr 5, 2026
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

3 participants