forked from TrueCloudLab/frostfs-api-go
[#366] rpc/client: Inherit read-write gRPC timeout from client
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
aa53fb7131
commit
49db0cfa03
2 changed files with 20 additions and 2 deletions
|
@ -15,7 +15,10 @@ func (c *Client) createGRPCClient() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.gRPCClient = grpc.New(grpc.WithClientConnection(c.conn))
|
c.gRPCClient = grpc.New(
|
||||||
|
grpc.WithClientConnection(c.conn),
|
||||||
|
grpc.WithRWTimeout(c.rwTimeout),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,17 +20,22 @@ type cfg struct {
|
||||||
addr string
|
addr string
|
||||||
|
|
||||||
dialTimeout time.Duration
|
dialTimeout time.Duration
|
||||||
|
rwTimeout time.Duration
|
||||||
|
|
||||||
tlsCfg *tls.Config
|
tlsCfg *tls.Config
|
||||||
|
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultDialTimeout = 5 * time.Second
|
const (
|
||||||
|
defaultDialTimeout = 5 * time.Second
|
||||||
|
defaultRWTimeout = 1 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
return &cfg{
|
return &cfg{
|
||||||
dialTimeout: defaultDialTimeout,
|
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
|
// WithTLSCfg returns option to specify
|
||||||
// TLS configuration.
|
// TLS configuration.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue