gRPC sends http2 pings on the transport to detect if the connection is down. If the ping is not acknowledged by the other side within a certain period, the connection will be close. Note that pings are only necessary when there's no activity on the connection.
For how to configure keepalive, see https://godoc.org/google.golang.org/grpc/keepalive for the options.
(The behavior described here is specific for gRPC-go, it might be slightly different in other languages.)
When there‘s no activity on a connection (note that an ongoing stream results in no activity when there’s no message being sent), after
Time, a ping will be sent by the client and the server will send a ping ack when it gets the ping. Client will wait for
Timeout, and check if there's any activity on the connection during this period (a ping ack is an activity).
Server has similar
Timeout settings as client. Server can also configure connection max-age. See server parameters for details.
Enforcement policy is a special setting on server side to protect server from malicious or misbehaving clients.
Server sends GOAWAY with ENHANCE_YOUR_CALM and close the connection when bad behaviors are detected: