Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

grpc

grpc-go

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.

like image 503
Saty Avatar asked Mar 26 '19 16:03

Saty


2 Answers

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

like image 130
Sudhanshu Ambastha Avatar answered Oct 23 '22 22:10

Sudhanshu Ambastha


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)
like image 37
jchavannes Avatar answered Oct 23 '22 22:10

jchavannes