Skip to content

Commit

Permalink
feat: add grpc client max payload size config options
Browse files Browse the repository at this point in the history
Closes #143
  • Loading branch information
palkan committed Nov 16, 2021
1 parent 816f7cf commit b05b82c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master

- Add `rpc_max_call_recv_size` and `rpc_max_call_send_size` options to allow modifying the corresponding limits for gRPC client connection. ([@palkan][])

## 1.1.3 (2021-09-16)

- Fixed potential deadlocks in Hub. ([@palkan][])
Expand Down
4 changes: 4 additions & 0 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func init() {
fs.StringVar(&defaults.RPC.Host, "rpc_host", "localhost:50051", "")
fs.IntVar(&defaults.RPC.Concurrency, "rpc_concurrency", 28, "")
fs.BoolVar(&defaults.RPC.EnableTLS, "rpc_enable_tls", false, "")
fs.IntVar(&defaults.RPC.MaxRecvSize, "rpc_max_call_recv_size", 0, "")
fs.IntVar(&defaults.RPC.MaxSendSize, "rpc_max_call_send_size", 0, "")
fs.StringVar(&headers, "headers", "cookie", "")

fs.IntVar(&defaults.WS.ReadBufferSize, "read_buffer_size", 1024, "")
Expand Down Expand Up @@ -157,6 +159,8 @@ OPTIONS
--rpc_host RPC service address, default: localhost:50051, env: ANYCABLE_RPC_HOST
--rpc_concurrency Max number of concurrent RPC request; should be slightly less than the RPC server concurrency, default: 28, env: ANYCABLE_RPC_CONCURRENCY
--rpc_enable_tls Enable client-side TLS with the RPC server, default: false, env: ANYCABLE_RPC_ENABLE_TLS
--rpc_max_call_recv_size Override default MaxCallRecvMsgSize for RPC client (bytes), default: none, env: ANYCABLE_RPC_MAX_CALL_RECV_SIZE
--rpc_max_call_send_size Override default MaxCallSendMsgSize for RPC client (bytes), default: none, env: ANYCABLE_RPC_MAX_CALL_SEND_SIZE
--headers List of headers to proxy to RPC, default: cookie, env: ANYCABLE_HEADERS
--disconnect_rate Max number of Disconnect calls per second, default: 100, env: ANYCABLE_DISCONNECT_RATE
Expand Down
4 changes: 4 additions & 0 deletions rpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type Config struct {
Concurrency int
// Enable client-side TLS on RPC connections?
EnableTLS bool
// Max recieve msg size (bytes)
MaxRecvSize int
// Max send msg size (bytes)
MaxSendSize int
}

// NewConfig builds a new config
Expand Down
21 changes: 18 additions & 3 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/grpc/credentials"

"crypto/tls"
)
Expand Down Expand Up @@ -140,17 +140,32 @@ func (c *Controller) Start() error {
if enableTLS {
tlsConfig := &tls.Config{
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS12,
}

dialOptions = append(dialOptions, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
} else {
dialOptions = append(dialOptions, grpc.WithInsecure())
}

var callOptions = []grpc.CallOption{}

// Zero is the default
if c.config.MaxRecvSize != 0 {
callOptions = append(callOptions, grpc.MaxCallRecvMsgSize(c.config.MaxRecvSize))
}

if c.config.MaxSendSize != 0 {
callOptions = append(callOptions, grpc.MaxCallSendMsgSize(c.config.MaxSendSize))
}

if len(callOptions) > 0 {
dialOptions = append(dialOptions, grpc.WithDefaultCallOptions(callOptions...))
}

conn, err := grpc.Dial(
host,
dialOptions...
dialOptions...,
)

c.initSemaphore(capacity)
Expand Down

0 comments on commit b05b82c

Please sign in to comment.