diff --git a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs index 4d8beea6e7f..7113c723299 100644 --- a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs +++ b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs @@ -165,12 +165,10 @@ void SerializeTimeoutException(IJsonRpcService service, IBufferWriter resu try { JsonRpcContext jsonRpcContext = JsonRpcContext.Http(jsonRpcUrl); - long totalResponseSize = 0; await foreach (JsonRpcResult result in jsonRpcProcessor.ProcessAsync(request, jsonRpcContext)) { Stream stream = jsonRpcConfig.BufferResponses ? new MemoryStream() : null; ICountingBufferWriter resultWriter = stream is not null ? new CountingStreamPipeWriter(stream) : new CountingPipeWriter(ctx.Response.BodyWriter); - try { ctx.Response.ContentType = "application/json"; @@ -198,9 +196,9 @@ void SerializeTimeoutException(IJsonRpcService service, IBufferWriter resu _ = jsonRpcLocalStats.ReportCall(entry.Report); // We reached the limit and don't want to responded to more request in the batch - if (!jsonRpcContext.IsAuthenticated && totalResponseSize > jsonRpcConfig.MaxBatchResponseBodySize) + if (!jsonRpcContext.IsAuthenticated && resultWriter.WrittenCount > jsonRpcConfig.MaxBatchResponseBodySize) { - if (logger.IsWarn) logger.Warn($"The max batch response body size exceeded. The current response size {totalResponseSize}, and the config setting is JsonRpc.{nameof(jsonRpcConfig.MaxBatchResponseBodySize)} = {jsonRpcConfig.MaxBatchResponseBodySize}"); + if (logger.IsWarn) logger.Warn($"The max batch response body size exceeded. The current response size {resultWriter.WrittenCount}, and the config setting is JsonRpc.{nameof(jsonRpcConfig.MaxBatchResponseBodySize)} = {jsonRpcConfig.MaxBatchResponseBodySize}"); enumerator.IsStopped = true; } } @@ -246,7 +244,6 @@ void SerializeTimeoutException(IJsonRpcService service, IBufferWriter resu ? new RpcReport("# collection serialization #", handlingTimeMicroseconds, true) : result.Report.Value, handlingTimeMicroseconds, resultWriter.WrittenCount); - totalResponseSize += resultWriter.WrittenCount; Interlocked.Add(ref Metrics.JsonRpcBytesSentHttp, resultWriter.WrittenCount); // There should be only one response because we don't expect multiple JSON tokens in the request