From 49db0cfa030cfbce33a6b6dc2f946fad376516c3 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 24 Dec 2021 13:18:57 +0300 Subject: [PATCH] [#366] rpc/client: Inherit read-write gRPC timeout from client Signed-off-by: Alex Vanin --- rpc/client/connect.go | 5 ++++- rpc/client/options.go | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rpc/client/connect.go b/rpc/client/connect.go index e80e422..1e36623 100644 --- a/rpc/client/connect.go +++ b/rpc/client/connect.go @@ -15,7 +15,10 @@ func (c *Client) createGRPCClient() (err error) { return } - c.gRPCClient = grpc.New(grpc.WithClientConnection(c.conn)) + c.gRPCClient = grpc.New( + grpc.WithClientConnection(c.conn), + grpc.WithRWTimeout(c.rwTimeout), + ) }) return diff --git a/rpc/client/options.go b/rpc/client/options.go index dd89f51..2c276dc 100644 --- a/rpc/client/options.go +++ b/rpc/client/options.go @@ -20,17 +20,22 @@ type cfg struct { addr string dialTimeout time.Duration + rwTimeout time.Duration tlsCfg *tls.Config conn *grpc.ClientConn } -const defaultDialTimeout = 5 * time.Second +const ( + defaultDialTimeout = 5 * time.Second + defaultRWTimeout = 1 * time.Minute +) func defaultCfg() *cfg { return &cfg{ dialTimeout: defaultDialTimeout, + rwTimeout: defaultRWTimeout, } } @@ -96,6 +101,16 @@ func WithDialTimeout(v time.Duration) Option { } } +// WithRWTimeout returns option to specify timeout +// for reading and writing single gRPC message. +func WithRWTimeout(v time.Duration) Option { + return func(c *cfg) { + if v > 0 { + c.rwTimeout = v + } + } +} + // WithTLSCfg returns option to specify // TLS configuration. //