doc/keepalive.md
The keepalive ping is a way to check if a channel is currently working by sending HTTP2 pings over the transport. It is sent periodically, and if the ping is not acknowledged by the peer within a certain timeout period, the transport is disconnected.
This guide documents the knobs within gRPC core to control the current behavior of the keepalive ping.
The keepalive ping in core is controlled by the following channel arguments -
On the server-side, the following additional channel arguments need to be configured -
IMPORTANT NOTE - For keepalive to work properly and as intended, all of the above channel arguments should be configured appropriately. The client-side keepalive settings should also be in agreement with the server-side settings. If a client sends pings more often than the server is willing to accept, the connection will be terminated with a GOAWAY frame with "too_many_pings" as the debug data.
Please refer to the C++ keepalive example for a sample way of setting these arguments.
| Channel Argument | Client | Server |
|---|---|---|
| GRPC_ARG_KEEPALIVE_TIME_MS | INT_MAX (disabled) | 7200000 (2 hours) |
| GRPC_ARG_KEEPALIVE_TIMEOUT_MS | 20000 (20 seconds) | 20000 (20 seconds) |
| GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS | 0 (false) | 0 (false) |
| GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA | 2 | 2 |
| GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS | N/A | 300000 (5 minutes) |
| GRPC_ARG_HTTP2_MAX_PING_STRIKES | N/A | 2 |
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS is false.GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA.ENHANCE_YOUR_CALM?
ENHANCE_YOUR_CALM if the client sends too many misbehaving pings as described in A8-client-side-keepalive.md. Some scenarios where this can happen are -
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS set to false while the client has set this to true resulting in keepalive pings being sent even when there is no call in flight.GRPC_ARG_KEEPALIVE_TIME_MS setting is lower than the server's GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS.GRPC_ARG_KEEPALIVE_TIME_MS and GRPC_ARG_KEEPALIVE_TIMEOUT_MS?
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS has not been set to 1(defaults to 0). If we require the endpoint to be able to send pings even when there are no ongoing RPCs, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS should be set to 1 as documented above.GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA to 0 will remove this limit.