From 65fe510df371febe59d7cece287513fd65b9883a Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 3 Jan 2022 17:05:41 -0500 Subject: [PATCH] GRPC client increase max message size --- grpc_client.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/grpc_client.go b/grpc_client.go index 842903c9..94b9f40c 100644 --- a/grpc_client.go +++ b/grpc_client.go @@ -3,7 +3,6 @@ package plugin import ( "crypto/tls" "fmt" - "math" "net" "time" @@ -14,6 +13,11 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" ) +// maxInt is defined here to allow 64-bit architectures to set message size +// limits greater than 2^31-1. This is used rather than [math.MaxInt] to support +// go versions < 1.17. +const maxInt = int(^uint(0) >> 1) + func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn, error), dialOpts ...grpc.DialOption) (*grpc.ClientConn, error) { // Build dialing options. opts := make([]grpc.DialOption, 0) @@ -34,8 +38,8 @@ func dialGRPCConn(tls *tls.Config, dialer func(string, time.Duration) (net.Conn, } opts = append(opts, - grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32)), - grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(math.MaxInt32))) + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxInt)), + grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(maxInt))) // Add our custom options if we have any opts = append(opts, dialOpts...)