[#366] rpc/client: Inherit read-write gRPC timeout from client

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-12-24 13:18:57 +03:00 committed by Alex Vanin
parent aa53fb7131
commit 49db0cfa03
2 changed files with 20 additions and 2 deletions

View file

@ -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

View file

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