1# Keepalive 2 3gRPC sends http2 pings on the transport to detect if the connection is down. If 4the ping is not acknowledged by the other side within a certain period, the 5connection will be close. Note that pings are only necessary when there's no 6activity on the connection. 7 8For how to configure keepalive, see 9https://godoc.org/google.golang.org/grpc/keepalive for the options. 10 11## What should I set? 12 13It should be sufficient for most users to set [client 14parameters](https://godoc.org/google.golang.org/grpc/keepalive) as a [dial 15option](https://godoc.org/google.golang.org/grpc#WithKeepaliveParams). 16 17## What will happen? 18 19(The behavior described here is specific for gRPC-go, it might be slightly 20different in other languages.) 21 22When there's no activity on a connection (note that an ongoing stream results in 23__no activity__ when there's no message being sent), after `Time`, a ping will 24be sent by the client and the server will send a ping ack when it gets the ping. 25Client will wait for `Timeout`, and check if there's any activity on the 26connection during this period (a ping ack is an activity). 27 28## What about server side? 29 30Server has similar `Time` and `Timeout` settings as client. Server can also 31configure connection max-age. See [server 32parameters](https://godoc.org/google.golang.org/grpc/keepalive#ServerParameters) 33for details. 34 35### Enforcement policy 36 37[Enforcement 38policy](https://godoc.org/google.golang.org/grpc/keepalive#EnforcementPolicy) is 39a special setting on server side to protect server from malicious or misbehaving 40clients. 41 42Server sends GOAWAY with ENHANCE_YOUR_CALM and close the connection when bad 43behaviors are detected: 44 - Client sends too frequent pings 45 - Client sends pings when there's no stream and this is disallowed by server 46 config 47