From 682142764668b3a9cfd60ec6f215afa441cd8d3f Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Thu, 25 Jul 2024 12:50:31 -0400 Subject: [PATCH] :bug: increase message size for grpc Signed-off-by: Pranav Gaikwad --- provider/grpc/provider.go | 18 ++++++++++++++---- provider/server.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/provider/grpc/provider.go b/provider/grpc/provider.go index eb21ae8c..1a9004bc 100644 --- a/provider/grpc/provider.go +++ b/provider/grpc/provider.go @@ -231,6 +231,8 @@ func (g *grpcProvider) Stop() { } func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.ReadCloser, error) { + // default is 4M, we use 8M + maxMessageSize := 1024 * 1024 * 8 // Here the Provider will start the GRPC Server if a binary is set. if config.BinaryPath != "" { port, err := freeport.GetFreePort() @@ -259,7 +261,9 @@ func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.Re if err != nil { return nil, nil, err } - conn, err := grpc.Dial(fmt.Sprintf("localhost:%v", port), grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.Dial(fmt.Sprintf("localhost:%v", port), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMessageSize)), + grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("did not connect: %v", err) } @@ -267,7 +271,9 @@ func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.Re } if config.Address != "" { if config.CertPath == "" { - conn, err := grpc.Dial(fmt.Sprintf(config.Address), grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.Dial(fmt.Sprintf(config.Address), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMessageSize)), + grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("did not connect: %v", err) } @@ -278,7 +284,9 @@ func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.Re return nil, nil, err } if config.JWTToken == "" { - conn, err := grpc.Dial(fmt.Sprintf(config.Address), grpc.WithTransportCredentials(creds)) + conn, err := grpc.Dial(fmt.Sprintf(config.Address), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMessageSize)), + grpc.WithTransportCredentials(creds)) if err != nil { log.Fatalf("did not connect: %v", err) } @@ -288,7 +296,9 @@ func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.Re i := &jwtTokeInterceptor{ Token: config.JWTToken, } - conn, err := grpc.Dial(fmt.Sprintf(config.Address), grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(i.unaryInterceptor)) + conn, err := grpc.Dial(fmt.Sprintf(config.Address), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMessageSize)), + grpc.WithTransportCredentials(creds), grpc.WithUnaryInterceptor(i.unaryInterceptor)) if err != nil { log.Fatalf("did not connect: %v", err) } diff --git a/provider/server.go b/provider/server.go index 82eae0eb..88ba91b4 100644 --- a/provider/server.go +++ b/provider/server.go @@ -116,7 +116,7 @@ func (s *server) Start(ctx context.Context) error { gs = grpc.NewServer(grpc.Creds(creds)) } } else if s.CertPath == "" && s.KeyPath == "" { - gs = grpc.NewServer() + gs = grpc.NewServer(grpc.MaxRecvMsgSize(1024*1024*24), grpc.MaxSendMsgSize(1024*1024*24)) } else { return fmt.Errorf("cert: %v, and key: %v are invalid", s.CertPath, s.KeyPath) }