grpc: received message larger than max (8653851 vs. 4194304)
Asked Answered
W

3

22

The problem:

I am getting this error while receiving message in grpc:

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

What I tried:

I gave the option to increase the size of the message to be received but it still gave the same error which means this setting of maximum size didn't work:

size := 1024 * 1024 * 12
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(size)))
conn, err := grpc.Dial(address, opts...)

Comments:

The default limit is 1024 * 1024 * 4 = 4194304 which is shown in the error message. I was expecting this limit to increase to 1024 * 1024 * 12 = 12582912 but clearly it didn't.

Woodenhead answered 26/3, 2019 at 16:49 Comment(1)
Strange, works for me. Can you reduce this to a complete reproducible example?Mllly
A
10

Please try updating grpc.MaxCallSendMsgSize(s int) on your client to enable your client send larger message. This worked for me.

Accidental answered 26/10, 2019 at 13:21 Comment(0)
H
3

Call options can be passed with each request.

For example, if your package is called queue and your method is called GetItems, then you would pass in the MaxCallRecvMsgSize option when calling GetItems.

Protobuf:

package queue;

service Queue {
    rpc GetItems (Request) returns (Items) {
    }
}

Go:

conn, err := grpc.Dial(address, opts...)
c := queue.NewQueueClient(s.Conn)
maxSizeOption := grpc.MaxCallRecvMsgSize(32*10e6)
items, err := c.GetItems(ctx, &queue.Request{}, maxSizeOption)
Hildahildagard answered 6/7, 2020 at 7:29 Comment(0)
A
1

I met the same question. My DialOption below sets MaxCallRecvMsgSize to be math.MaxInt64. But it doesn't work.

The reason is grpc.WithChainUnaryInterceptor(chains...) appended will be executed firstly when the client call GRPC functons, and the client will jump over the grpc.WithDefaultCallOptions. So you should set MaxCallRecvMsgSize in chains or remove grpc.WithChainUnaryInterceptor.

func NewClient() (promotion.PromotionClient, error) {
    conn, err := grpc.Dial("address", DialogOptions()...)
    if err != nil {
        return nil, err
    }
    return promotion.NewPromotionClient(conn), nil
}

func DialogOptions(chains ...grpc.UnaryClientInterceptor) []grpc.DialOption {
    chains = append(chains, userinfo.UnaryClientInterceptor())
    return []grpc.DialOption{
        grpc.WithDefaultCallOptions(
            grpc.MaxCallRecvMsgSize(math.MaxInt64),
            grpc.MaxCallSendMsgSize(math.MaxInt64),
        ),
        grpc.WithChainUnaryInterceptor(chains...),
    }
}
Abbie answered 7/10, 2023 at 9:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.