frostfs-api-go/rpc/grpc/options.go
Alex Vanin aa53fb7131 [#366] rpc/grpc: Perform read-write message operations with timeout
Remote gRPC server may not return or accept data for a while. gRPC
solves this issue with timeout in context. However, the context is
used for entire gRPC method invocation. Unfortunately the duration
of requests with streams can't be estimated easily.

To solve this issue we can specify timeouts for every message read
and write. Single message has size limit so timeout can be related
to that.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-12-28 12:49:31 +03:00

36 lines
632 B
Go

package grpc
import (
"time"
"google.golang.org/grpc"
)
const defaultRWTimeout = 1 * time.Minute
type cfg struct {
con *grpc.ClientConn
rwTimeout time.Duration
}
func defaultCfg() *cfg {
return &cfg{
rwTimeout: defaultRWTimeout,
}
}
// WithClientConnection returns option to set gRPC connection
// to the remote server.
func WithClientConnection(con *grpc.ClientConn) Option {
return func(c *cfg) {
c.con = con
}
}
// WithRWTimeout returns option to specify rwTimeout
// for reading and writing single gRPC message.
func WithRWTimeout(t time.Duration) Option {
return func(c *cfg) {
c.rwTimeout = t
}
}