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. //