From 81e1f479ea8d71057d10c8d477c62bbe9cffd7dc Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 23 Apr 2024 15:35:43 +0800 Subject: [PATCH] grpc: allow client send consecutive pings in every 5 seconds Signed-off-by: yongman --- pkg/mcs/utils/util.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index b6ac2eb37e5..3881ab77ef7 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -42,6 +42,7 @@ import ( "go.etcd.io/etcd/pkg/types" "go.uber.org/zap" "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" ) const ( @@ -229,7 +230,14 @@ func StartGRPCAndHTTPServers(s server, serverReadyChan chan<- struct{}, l net.Li httpListener = mux.Match(cmux.HTTP1()) } - grpcServer := grpc.NewServer() + grpcServer := grpc.NewServer( + // Allow clients send consecutive pings in every 5 seconds. + // The default value of MinTime is 5 minutes, + // which is too long compared with 10 seconds of TiKV's pd client keepalive time. + grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ + MinTime: 5 * time.Second, + }), + ) s.SetGRPCServer(grpcServer) s.RegisterGRPCService(grpcServer) diagnosticspb.RegisterDiagnosticsServer(grpcServer, s)