-
Notifications
You must be signed in to change notification settings - Fork 2
/
keepalive.go
52 lines (46 loc) · 1.85 KB
/
keepalive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rpc
import (
"time"
"github.com/journeymidnight/nentropy/helper"
"google.golang.org/grpc/keepalive"
)
// 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: helper.NetworkTimeout,
// 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: helper.NetworkTimeout,
// Do the pings even when there are no ongoing RPCs.
PermitWithoutStream: true,
}
var ServerKeepalive = keepalive.ServerParameters{
// Send periodic pings on the connection.
Time: helper.NetworkTimeout,
// 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.
Timeout: helper.NetworkTimeout,
}
// By default, gRPC disconnects clients that send "too many" pings,
// but we don't really care about that, so configure the server to be
// as permissive as possible.
var ServerEnforcement = keepalive.EnforcementPolicy{
MinTime: time.Nanosecond,
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,
}