@@ -18,6 +18,7 @@ import (
18
18
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/fromproto"
19
19
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
20
20
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/toproto"
21
+ "google.golang.org/grpc"
21
22
22
23
"github.com/hashicorp/go-hclog"
23
24
"github.com/hashicorp/go-plugin"
@@ -59,6 +60,26 @@ const (
59
60
envTfReattachProviders = "TF_REATTACH_PROVIDERS"
60
61
)
61
62
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
+
62
83
// ServeOpt is an interface for defining options that can be passed to the
63
84
// Serve function. Each implementation modifies the ServeConfig being
64
85
// 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
240
261
GRPCProvider : serverFactory ,
241
262
},
242
263
},
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
+ },
244
270
}
245
271
246
272
if conf .logger != nil {
0 commit comments