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:
anzzyspeaksgit 2026-03-13 09:09:23 +00:00
parent eaa9418ac1
commit 41ad0adfec

View file

@ -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)