rpc: count error responses towards batch response size limit#33815
Open
handfuzzer wants to merge 1 commit intoethereum:masterfrom
Open
rpc: count error responses towards batch response size limit#33815handfuzzer wants to merge 1 commit intoethereum:masterfrom
handfuzzer wants to merge 1 commit intoethereum:masterfrom
Conversation
fjl
requested changes
Feb 12, 2026
Contributor
fjl
left a comment
There was a problem hiding this comment.
The idea is good, but I don't like that jsonError.Data has to be serialized twice to get the size. We have to force serialization of that field earlier and store it as json.RawMessage, then we could compute the size of the error without encoding it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33814
Description
This PR fixes batch response size limit accounting for error responses.
Currently,
(*handler).handleBatchonly addslen(resp.Result)toresponseBytes. For error responses,resp.Resultis nil, so largeerror.datapayloads are not counted and batch responses may exceedmaxResponseSize.Changes:
rpc/handler.go: include error responses inresponseBytesaccounting.rpc: add regression testTestBatchResponseSizeLimitCountsErrorResponses.Expected behaviour
When
Server.SetBatchLimits(itemLimit, maxResponseSize)(orWithBatchResponseSizeLimit) is configured, the server should stop processing additional items in a batch once the cumulative response size exceedsmaxResponseSize.This limit should apply uniformly to both:
result)error, includingerror.dataviarpc.DataError)Once the limit is exceeded, subsequent batch items should return
-32003 (response too large).Actual behaviour
In
rpc/handler.go,(*handler).handleBatchonly accounts forlen(resp.Result)when accumulatingresponseBytes.For error responses:
resp.Resultisnilerror.data) are not counted towardBatchResponseMaxSizeAs a result, batch responses can significantly exceed
maxResponseSize, and-32003 (response too large)is not reliably returned for later batch items.Proposed fix
In
rpc/handler.go((*handler).handleBatch):responseBytesresp.ErrormaxResponseSizeconsistently for both success and error responsesConceptually:
(Exact implementation details can be refined.)
Tests
Add a regression test in
rpc/:TestBatchResponseSizeLimitCountsErrorResponsesVerify that large error responses:
-32003-32003Run with: