Skip to content

Commit ecf4b08

Browse files
authored
Increase gRPC maximum message size send and receive limits to 256MB (#139)
Reference: #106
1 parent bf7516c commit ecf4b08

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

.changelog/139.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
tfprotov5/tf5server: Increased maximum gRPC send and receive message size limit to 256MB
3+
```
4+
5+
```release-note:enhancement
6+
tfprotov6/tf6server: Increased maximum gRPC send and receive message size limit to 256MB
7+
```

tfprotov5/tf5server/server.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/fromproto"
1919
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
2020
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/toproto"
21+
"google.golang.org/grpc"
2122

2223
"github.com/hashicorp/go-hclog"
2324
"github.com/hashicorp/go-plugin"
@@ -59,6 +60,26 @@ const (
5960
envTfReattachProviders = "TF_REATTACH_PROVIDERS"
6061
)
6162

63+
const (
64+
// grpcMaxMessageSize is the maximum gRPC send and receive message sizes
65+
// for the server.
66+
//
67+
// This 256MB value is arbitrarily raised from the default message sizes of
68+
// 4MB to account for advanced use cases, but arbitrarily lowered from
69+
// MaxInt32 (or similar) to prevent incorrect server implementations from
70+
// exhausting resources in common execution environments. Receiving a gRPC
71+
// message size error is preferable for troubleshooting over determining
72+
// why an execution environment may have terminated the process via its
73+
// memory management processes, such as oom-killer on Linux.
74+
//
75+
// This value is kept as constant over allowing server configurability
76+
// since there are many factors that influence message size, such as
77+
// Terraform configuration and state data. If larger message size use
78+
// cases appear, other gRPC options should be explored, such as
79+
// implementing streaming RPCs and messages.
80+
grpcMaxMessageSize = 256 << 20
81+
)
82+
6283
// ServeOpt is an interface for defining options that can be passed to the
6384
// Serve function. Each implementation modifies the ServeConfig being
6485
// generated. A slice of ServeOpts then, cumulatively applied, render a full
@@ -240,7 +261,12 @@ func Serve(name string, serverFactory func() tfprotov5.ProviderServer, opts ...S
240261
GRPCProvider: serverFactory,
241262
},
242263
},
243-
GRPCServer: plugin.DefaultGRPCServer,
264+
GRPCServer: func(opts []grpc.ServerOption) *grpc.Server {
265+
opts = append(opts, grpc.MaxRecvMsgSize(grpcMaxMessageSize))
266+
opts = append(opts, grpc.MaxSendMsgSize(grpcMaxMessageSize))
267+
268+
return grpc.NewServer(opts...)
269+
},
244270
}
245271

246272
if conf.logger != nil {

tfprotov6/tf6server/server.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/fromproto"
1919
"github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6"
2020
"github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/toproto"
21+
"google.golang.org/grpc"
2122

2223
"github.com/hashicorp/go-hclog"
2324
"github.com/hashicorp/go-plugin"
@@ -59,6 +60,26 @@ const (
5960
envTfReattachProviders = "TF_REATTACH_PROVIDERS"
6061
)
6162

63+
const (
64+
// grpcMaxMessageSize is the maximum gRPC send and receive message sizes
65+
// for the server.
66+
//
67+
// This 256MB value is arbitrarily raised from the default message sizes of
68+
// 4MB to account for advanced use cases, but arbitrarily lowered from
69+
// MaxInt32 (or similar) to prevent incorrect server implementations from
70+
// exhausting resources in common execution environments. Receiving a gRPC
71+
// message size error is preferable for troubleshooting over determining
72+
// why an execution environment may have terminated the process via its
73+
// memory management processes, such as oom-killer on Linux.
74+
//
75+
// This value is kept as constant over allowing server configurability
76+
// since there are many factors that influence message size, such as
77+
// Terraform configuration and state data. If larger message size use
78+
// cases appear, other gRPC options should be explored, such as
79+
// implementing streaming RPCs and messages.
80+
grpcMaxMessageSize = 256 << 20
81+
)
82+
6283
// ServeOpt is an interface for defining options that can be passed to the
6384
// Serve function. Each implementation modifies the ServeConfig being
6485
// generated. A slice of ServeOpts then, cumulatively applied, render a full
@@ -242,7 +263,12 @@ func Serve(name string, serverFactory func() tfprotov6.ProviderServer, opts ...S
242263
Name: name,
243264
},
244265
},
245-
GRPCServer: plugin.DefaultGRPCServer,
266+
GRPCServer: func(opts []grpc.ServerOption) *grpc.Server {
267+
opts = append(opts, grpc.MaxRecvMsgSize(grpcMaxMessageSize))
268+
opts = append(opts, grpc.MaxSendMsgSize(grpcMaxMessageSize))
269+
270+
return grpc.NewServer(opts...)
271+
},
246272
}
247273

248274
if conf.logger != nil {

0 commit comments

Comments
 (0)