go resource_error ai_generated true

rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5242881 vs. 4194304)

ID: go/grpc-max-message-size-exceeded

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-07-03First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
google.golang.org/grpc v1.50+ active — — —

Root Cause

The serialized protobuf message exceeds the default 4 MiB receive limit on either the client or server side.

generic

中文

序列化后的 protobuf 消息超过了客户端或服务器端默认的 4 MiB 接收限制。

Workarounds

  1. 95% success
    // server
    s := grpc.NewServer(grpc.MaxRecvMsgSize(16*1024*1024), grpc.MaxSendMsgSize(16*1024*1024))
    // client
    conn, _ := grpc.NewClient(addr,
        grpc.WithDefaultCallOptions(
            grpc.MaxCallRecvMsgSize(16*1024*1024),
            grpc.MaxCallSendMsgSize(16*1024*1024),
        ),
    )
  2. 88% success
    stream, err := client.Upload(ctx)
    if err != nil { return err }
    for _, chunk := range chunks {
        if err := stream.Send(&pb.Chunk{Data: chunk}); err != nil { return err }
    }
    _, err = stream.CloseAndRecv()

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Still hits the limit if reassembly happens before unmarshal; also doubles memory pressure.

  2. 65% fail

    The limit is checked on the decompressed wire size after gRPC's own compression; ineffective for incompressible data.