mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
rpc: fix BatchResponseMaxSize not accounting for error responses
Closes #33814 When `Server.SetBatchLimits(itemLimit, maxResponseSize)` is configured, `(*handler).handleBatch` previously only accumulated `len(resp.Result)` when determining if the `responseBytes` limit was exceeded. Because `resp.Result` is `nil` for error responses, large `rpc.DataError` payloads were not counted towards the maximum size limit, allowing batch responses to bypass memory consumption bounds. This PR adds the size of the error message and the approximated serialized size of `ErrorData` to the `responseBytes` total so that the `-32003 (response too large)` circuit-breaker trips accurately for both successful and error responses. AI Disclosure: This PR was generated autonomously by anzzyspeaksgit.
This commit is contained in:
parent
eaa9418ac1
commit
41ad0adfec
1 changed files with 8 additions and 0 deletions
|
|
@ -238,6 +238,14 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
|||
callBuffer.pushResponse(resp)
|
||||
if resp != nil && h.batchResponseMaxSize != 0 {
|
||||
responseBytes += len(resp.Result)
|
||||
if resp.Error != nil {
|
||||
responseBytes += len(resp.Error.Message)
|
||||
if resp.Error.Data != nil {
|
||||
if b, err := json.Marshal(resp.Error.Data); err == nil {
|
||||
responseBytes += len(b)
|
||||
}
|
||||
}
|
||||
}
|
||||
if responseBytes > h.batchResponseMaxSize {
|
||||
err := &internalServerError{errcodeResponseTooLarge, errMsgResponseTooLarge}
|
||||
callBuffer.respondWithError(cp.ctx, h.conn, err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue