Skip to content

Commit 46eb233

Browse files
committed
Enhance gRPC message handling by setting max message size to 64MB
- Updated gRPC client and server configurations to support larger message sizes, ensuring compatibility with large configurations and user data. - Added constants for max receive and send message sizes in both the client and server setup.
1 parent d8382db commit 46eb233

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

controller/rpc/rpc_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ func TestMain(m *testing.M) {
6464
}
6565

6666
creds := credentials.NewClientTLSFromCert(certPool, "")
67+
// Set max message size to 64MB to match server configuration
68+
const maxMsgSize = 64 * 1024 * 1024 // 64MB
6769
opts := []grpc.DialOption{
6870
grpc.WithTransportCredentials(creds),
71+
grpc.WithDefaultCallOptions(
72+
grpc.MaxCallRecvMsgSize(maxMsgSize),
73+
grpc.MaxCallSendMsgSize(maxMsgSize),
74+
),
6975
}
7076

7177
conn, err := grpc.NewClient(addr, opts...)

controller/rpc/service.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"context"
55
"crypto/tls"
66
"fmt"
7+
"log"
8+
"net"
9+
710
"github.com/pasarguard/node/common"
811
"github.com/pasarguard/node/config"
912
"github.com/pasarguard/node/controller"
1013
"google.golang.org/grpc"
1114
"google.golang.org/grpc/credentials"
12-
"log"
13-
"net"
1415
)
1516

1617
type Service struct {
@@ -30,8 +31,12 @@ func StartGRPCListener(tlsConfig *tls.Config, addr string, cfg *config.Config) (
3031
creds := credentials.NewTLS(tlsConfig)
3132

3233
// Create the gRPC server with conditional middleware
34+
// Set max message size to 64MB to handle large configs and user data
35+
const maxMsgSize = 64 * 1024 * 1024 // 64MB
3336
grpcServer := grpc.NewServer(
3437
grpc.Creds(creds),
38+
grpc.MaxRecvMsgSize(maxMsgSize),
39+
grpc.MaxSendMsgSize(maxMsgSize),
3540
grpc.UnaryInterceptor(ConditionalMiddleware(s)),
3641
grpc.StreamInterceptor(ConditionalStreamMiddleware(s)),
3742
)

0 commit comments

Comments
 (0)