From a975db9349abe465fb171dd6690805aa1d131faf Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 22 Jul 2019 12:44:59 -0700 Subject: [PATCH] grpclb: enable keepalive (#2918) So grpclb client will reconnect when the connection is down (e.g. proxy drops the server side connection but keeps the client side). --- balancer/grpclb/grpclb_remote_balancer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/balancer/grpclb/grpclb_remote_balancer.go b/balancer/grpclb/grpclb_remote_balancer.go index 304bce664af3..1d1e88488744 100644 --- a/balancer/grpclb/grpclb_remote_balancer.go +++ b/balancer/grpclb/grpclb_remote_balancer.go @@ -34,6 +34,7 @@ import ( "google.golang.org/grpc/grpclog" "google.golang.org/grpc/internal" "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/keepalive" "google.golang.org/grpc/metadata" "google.golang.org/grpc/resolver" ) @@ -349,6 +350,13 @@ func (lb *lbBalancer) dialRemoteLB(remoteLBName string) { dopts = append(dopts, grpc.WithChannelzParentID(lb.opt.ChannelzParentID)) } + // Enable Keepalive for grpclb client. + dopts = append(dopts, grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: 20 * time.Second, + Timeout: 10 * time.Second, + PermitWithoutStream: true, + })) + // DialContext using manualResolver.Scheme, which is a random scheme // generated when init grpclb. The target scheme here is not important. //