diff --git a/changelog/unreleased/configurable_max_message_size.md b/changelog/unreleased/configurable_max_message_size.md new file mode 100644 index 00000000000..3b889af552e --- /dev/null +++ b/changelog/unreleased/configurable_max_message_size.md @@ -0,0 +1,6 @@ +Enhancement: Allow configuring the max size of grpc messages + +We added a possibility to make the max size of grpc messsages configurable. +It is only configurable via envvar `OCIS_GRPC_MAX_MESSAGE_SIZE` . It is recommended to use this envvar only temporarily. + +https://github.com/cs3org/reva/pull/4074 diff --git a/pkg/rgrpc/todo/pool/connection.go b/pkg/rgrpc/todo/pool/connection.go index 253ee7f8f7a..ea7488f63b7 100644 --- a/pkg/rgrpc/todo/pool/connection.go +++ b/pkg/rgrpc/todo/pool/connection.go @@ -20,8 +20,11 @@ package pool import ( "crypto/tls" + "os" + "strconv" rtrace "github.com/cs3org/reva/v2/pkg/trace" + "github.com/pkg/errors" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -29,13 +32,12 @@ import ( ) var ( - maxCallRecvMsgSize = 10240000 + _defaultMaxCallRecvMsgSize = 10240000 ) // NewConn creates a new connection to a grpc server // with open census tracing support. // TODO(labkode): make grpc tls configurable. -// TODO make maxCallRecvMsgSize configurable, raised from the default 4MB to be able to list 10k files func NewConn(address string, opts ...Option) (*grpc.ClientConn, error) { options := ClientOptions{} @@ -69,11 +71,24 @@ func NewConn(address string, opts ...Option) (*grpc.ClientConn, error) { } } + // NOTE: We need to configure some grpc options in a central place. + // If many services configure the (e.g.) gateway client differently, one will be pick randomly. This leads to inconsistencies when using the single binary. + // To avoid inconsistencies and race conditions we get the configuration here. + // Please do NOT follow the pattern of calling `os.Getenv` in the wild without consulting docu team first. + maxRcvMsgSize := _defaultMaxCallRecvMsgSize + if e := os.Getenv("OCIS_GRPC_MAX_RECEIVED_MESSAGE_SIZE"); e != "" { + s, err := strconv.Atoi(e) + if err != nil || s <= 0 { + return nil, errors.Wrap(err, "grpc max message size is not a valid int") + } + maxRcvMsgSize = s + } + conn, err := grpc.Dial( address, grpc.WithTransportCredentials(cred), grpc.WithDefaultCallOptions( - grpc.MaxCallRecvMsgSize(maxCallRecvMsgSize), + grpc.MaxCallRecvMsgSize(maxRcvMsgSize), ), grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( otelgrpc.WithTracerProvider(