Skip to content

Commit

Permalink
rpc: use gRPC enforced minimum keepalive timeout
Browse files Browse the repository at this point in the history
Before this commit we'd experience the following annoying log message from gRPC
every time we create a new connection telling us that our setting is being
ignored.

```
Adjusting keepalive ping interval to minimum period of 10s
```

Release note: None
  • Loading branch information
ajwerner committed Aug 14, 2019
1 parent e445511 commit b73abf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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

0 comments on commit b73abf6

Please sign in to comment.