connections: make use of keepalive options

This commit is contained in:
Roman Khimov 2021-04-29 22:58:54 +03:00 committed by Roman Khimov
parent afbb9d51f1
commit f99f9e88a7
2 changed files with 16 additions and 1 deletions

3
app.go
View file

@ -114,6 +114,9 @@ func newApp(ctx context.Context, opt ...Option) App {
NodeRequestTimeout: a.cfg.GetDuration(cfgReqTimeout),
ClientRebalanceInterval: a.cfg.GetDuration(cfgRebalance),
SessionExpirationEpoch: math.MaxUint64,
KeepaliveTime: a.cfg.GetDuration(cfgKeepaliveTime),
KeepaliveTimeout: a.cfg.GetDuration(cfgKeepaliveTimeout),
KeepalivePermitWoStream: a.cfg.GetBool(cfgKeepalivePermitWithoutStream),
}
pool, err := pb.Build(ctx, opts)
if err != nil {

View file

@ -12,6 +12,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
type PoolBuilderOptions struct {
@ -19,6 +20,9 @@ type PoolBuilderOptions struct {
NodeConnectionTimeout time.Duration
NodeRequestTimeout time.Duration
ClientRebalanceInterval time.Duration
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
KeepalivePermitWoStream bool
SessionExpirationEpoch uint64
weights []float64
connections []*grpc.ClientConn
@ -51,7 +55,15 @@ func (pb *PoolBuilder) Build(ctx context.Context, options *PoolBuilderOptions) (
con, err := func() (*grpc.ClientConn, error) {
toctx, c := context.WithTimeout(ctx, options.NodeConnectionTimeout)
defer c()
return grpc.DialContext(toctx, address, grpc.WithInsecure(), grpc.WithBlock())
return grpc.DialContext(toctx, address,
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: options.KeepaliveTime,
Timeout: options.KeepaliveTimeout,
PermitWithoutStream: options.KeepalivePermitWoStream,
}),
)
}()
if err != nil {
return nil, err