Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: use gRPC enforced minimum keepalive timeout #39669

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/rpc/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ type grpcKeepaliveTestCase struct {
func grpcRunKeepaliveTestCase(testCtx context.Context, c grpcKeepaliveTestCase) error {
var cKeepalive keepalive.ClientParameters
if c.cKeepalive {
cKeepalive = clientTestingKeepalive
cKeepalive = clientKeepalive
}
var sKeepalive keepalive.ServerParameters
if c.sKeepalive {
Expand Down
17 changes: 8 additions & 9 deletions pkg/rpc/keepalive.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ import (
"google.golang.org/grpc/keepalive"
)

// 10 seconds is the minimum keepalive interval permitted by gRPC.
// Setting it to a value lower than this will lead to gRPC adjusting to this
// value and annoyingly logging "Adjusting keepalive ping interval to minimum
// period of 10s". See grpc/grpc-go#2642.
const minimumClientKeepaliveInterval = 10 * time.Second

// To prevent unidirectional network partitions from keeping an unhealthy
// connection alive, we use both client-side and server-side keepalive pings.
var clientKeepalive = keepalive.ClientParameters{
// Send periodic pings on the connection.
Time: base.NetworkTimeout,
Time: minimumClientKeepaliveInterval,
// If the pings don't get a response within the timeout, we might be
// experiencing a network partition. gRPC will close the transport-level
// connection and all the pending RPCs (which may not have timeouts) will
// fail eagerly. gRPC will then reconnect the transport transparently.
Timeout: base.NetworkTimeout,
Timeout: minimumClientKeepaliveInterval,
// Do the pings even when there are no ongoing RPCs.
PermitWithoutStream: true,
}
Expand All @@ -48,13 +54,6 @@ var serverEnforcement = keepalive.EnforcementPolicy{
PermitWithoutStream: true,
}

// These aggressively low keepalive timeouts ensure that tests which use
// them don't take too long.
var clientTestingKeepalive = keepalive.ClientParameters{
Time: 200 * time.Millisecond,
Timeout: 300 * time.Millisecond,
PermitWithoutStream: true,
}
var serverTestingKeepalive = keepalive.ServerParameters{
Time: 200 * time.Millisecond,
Timeout: 300 * time.Millisecond,
Expand Down