ResourceExhausted dotnet protocol_error ai_generated true

Grpc.Core.RpcException: Status(StatusCode="ResourceExhausted", Detail="Received message larger than max (4194304 vs. 4194304)")

ID: dotnet/grpc-client-max-message-size

Also available as: JSON · Markdown · 中文
90%Fix Rate
90%Confidence
1Evidence
2023-02-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
.NET 6.0 active
.NET 7.0 active
.NET 8.0 active
Grpc.Net.Client 2.49+ active
Grpc.AspNetCore 2.49+ active

Root Cause

The gRPC client or server has a default maximum message size of 4 MB, and the response payload exceeds this limit, causing the channel to reject it.

generic

中文

gRPC客户端或服务器默认最大消息大小为4 MB,响应负载超过此限制,导致通道拒绝。

Official Documentation

https://learn.microsoft.com/en-us/aspnet/core/grpc/configuration?view=aspnetcore-8.0#configure-maximum-message-size

Workarounds

  1. 95% success Increase MaxReceiveMessageSize on the client and MaxSendMessageSize on the server to a larger value (e.g., 10 MB) in the gRPC channel and service options.
    Increase MaxReceiveMessageSize on the client and MaxSendMessageSize on the server to a larger value (e.g., 10 MB) in the gRPC channel and service options.
  2. 85% success Stream the large payload using server-streaming gRPC instead of unary calls to avoid hitting the message size limit.
    Stream the large payload using server-streaming gRPC instead of unary calls to avoid hitting the message size limit.

中文步骤

  1. Increase MaxReceiveMessageSize on the client and MaxSendMessageSize on the server to a larger value (e.g., 10 MB) in the gRPC channel and service options.
  2. Stream the large payload using server-streaming gRPC instead of unary calls to avoid hitting the message size limit.

Dead Ends

Common approaches that don't work:

  1. Increasing the client's MaxReceiveMessageSize without adjusting the server's MaxSendMessageSize 70% fail

    Both client and server enforce limits; if only one side is increased, the other side still rejects the message.

  2. Disabling compression on the gRPC channel to reduce message size 40% fail

    Compression reduces size but does not eliminate the hard limit; large payloads still exceed 4 MB.