Skip to content

Commit

Permalink
allow setting a grace period as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaudreault committed Aug 14, 2017
1 parent 4ad01c5 commit b64a970
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions go/vt/servenv/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var (
// GRPCMaxConnectionAge is the maximum age of a client connection, before GoAway is sent.
// This is useful for L4 loadbalancing to ensure rebalancing after scaling.
GRPCMaxConnectionAge *time.Duration

// GRPCMaxConnectionAgeGrace is an additional grace period after GRPCMaxConnectionAge, after which
// connections are forcibly closed.
GRPCMaxConnectionAgeGrace *time.Duration
)

// isGRPCEnabled returns true if gRPC server is set
Expand Down Expand Up @@ -116,9 +120,13 @@ func createGRPCServer() {
}

if GRPCMaxConnectionAge != nil {
opts = append(opts, grpc.KeepaliveParams(keepalive.ServerParameters{
ka := keepalive.ServerParameters{
MaxConnectionAge: *GRPCMaxConnectionAge,
}))
}
if GRPCMaxConnectionAgeGrace != nil {
ka.MaxConnectionAgeGrace = *GRPCMaxConnectionAgeGrace
}
opts = append(opts, grpc.KeepaliveParams(ka))
}

GRPCServer = grpc.NewServer(opts...)
Expand Down Expand Up @@ -158,6 +166,7 @@ func RegisterGRPCFlags() {
GRPCMaxMessageSize = flag.Int("grpc_max_message_size", 4*1024*1024, "Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'.")
// Default is effectively infinity, as defined in grpc.
GRPCMaxConnectionAge = flag.Duration("grpc_max_connection_age", time.Duration(math.MaxInt64), "Maximum age of a client connection before GoAway is sent.")
GRPCMaxConnectionAgeGrace = flag.Duration("grpc_max_connection_age_grace", time.Duration(math.MaxInt64), "Additional grace period after grpc_max_connection_age, after which connections are forcibly closed.")
}

// GRPCCheckServiceMap returns if we should register a gRPC service
Expand Down

0 comments on commit b64a970

Please sign in to comment.