From f99f9e88a7e671aa066580cbcafdd649250eaef9 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 29 Apr 2021 22:58:54 +0300 Subject: [PATCH] connections: make use of keepalive options --- app.go | 3 +++ connections/pool.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 5c352e9..b42343b 100644 --- a/app.go +++ b/app.go @@ -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 { diff --git a/connections/pool.go b/connections/pool.go index 15e22f4..5765d5f 100644 --- a/connections/pool.go +++ b/connections/pool.go @@ -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