From 2fd1c1c08ad54369cf4e5e002ad163630c77ac53 Mon Sep 17 00:00:00 2001 From: Davide Lienhard Date: Tue, 6 Aug 2024 10:19:21 +0200 Subject: [PATCH 1/2] added maximum Message size serveoption Signed-off-by: Davide Lienhard --- sdk.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/sdk.go b/sdk.go index 5b4aadb..447801c 100644 --- a/sdk.go +++ b/sdk.go @@ -36,21 +36,23 @@ import ( // Default ServeOptions. const ( - DefaultNetwork = "tcp" - DefaultAddress = ":9443" + DefaultNetwork = "tcp" + DefaultAddress = ":9443" + DefaultMaxRecvMsgSize = 4096 ) // ServeOptions configure how a Function is served. type ServeOptions struct { - Network string - Address string - Credentials credentials.TransportCredentials + Network string + Address string + MaxRecvMsgSize int + Credentials credentials.TransportCredentials } // A ServeOption configures how a Function is served. type ServeOption func(o *ServeOptions) error -// Listen configures the network and address on which the Function will +// Listen configures the network, address and maximum message size on which the Function will // listen for RunFunctionRequests. func Listen(network, address string) ServeOption { return func(o *ServeOptions) error { @@ -114,12 +116,22 @@ func Insecure(insecure bool) ServeOption { } } +// MaxMsgSize returns a ServeOption to set the max message size in bytes the server can receive. +// If this is not set, gRPC uses the default limit. +func MaxRecvMessageSize(sz int) ServeOption { + return func(o *ServeOptions) error { + o.MaxRecvMsgSize = sz + return nil + } +} + // Serve the supplied Function by creating a gRPC server and listening for // RunFunctionRequests. Blocks until the server returns an error. func Serve(fn v1beta1.FunctionRunnerServiceServer, o ...ServeOption) error { so := &ServeOptions{ - Network: DefaultNetwork, - Address: DefaultAddress, + Network: DefaultNetwork, + Address: DefaultAddress, + MaxRecvMsgSize: DefaultMaxRecvMsgSize, } for _, fn := range o { @@ -137,7 +149,7 @@ func Serve(fn v1beta1.FunctionRunnerServiceServer, o ...ServeOption) error { return errors.Wrapf(err, "cannot listen for %s connections at address %q", so.Network, so.Address) } - srv := grpc.NewServer(grpc.Creds(so.Credentials)) + srv := grpc.NewServer(grpc.MaxRecvMsgSize(so.MaxRecvMsgSize), grpc.Creds(so.Credentials)) reflection.Register(srv) v1beta1.RegisterFunctionRunnerServiceServer(srv, fn) return errors.Wrap(srv.Serve(lis), "cannot serve mTLS gRPC connections") From f185cd50b0dba59c89fd20b91825220cbbba8f98 Mon Sep 17 00:00:00 2001 From: davidelienhard Date: Fri, 9 Aug 2024 09:05:15 +0200 Subject: [PATCH 2/2] Update sdk.go Signed-off-by: Davide Lienhard --- sdk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk.go b/sdk.go index 447801c..0b20a59 100644 --- a/sdk.go +++ b/sdk.go @@ -116,7 +116,7 @@ func Insecure(insecure bool) ServeOption { } } -// MaxMsgSize returns a ServeOption to set the max message size in bytes the server can receive. +// MaxRecvMessageSize returns a ServeOption to set the max message size in bytes the server can receive. // If this is not set, gRPC uses the default limit. func MaxRecvMessageSize(sz int) ServeOption { return func(o *ServeOptions) error {