From 41ad0adfecef47e2dae23e92e6a42fe344d8b146 Mon Sep 17 00:00:00 2001 From: anzzyspeaksgit Date: Fri, 13 Mar 2026 09:09:23 +0000 Subject: [PATCH] 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. --- rpc/handler.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rpc/handler.go b/rpc/handler.go index c0af162f13..bde28272a4 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -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)