gRPC keep-alive timeout configuration impact on connection-level timeout behavior
0 reputation · 06 Apr 2022, 02:19 UTC
0 reputation · 06 Apr 2022, 02:19 UTC
When operating gRPC inside a service mesh, administrators often configure both per‑channel keep‑alive settings and connection‑level idle timeouts enforced by sidecar proxies or load balancers. The goal is to maintain healthy long‑lived streams while preventing stale connections from consuming resources. However, the interaction between the keep‑alive ping interval and the connection‑level timeout is not clearly defined in the gRPC specification, leading to scenarios where a keep‑alive reset may mask an idle timeout or cause the connection to be considered alive when the mesh has already marked it for termination.
This ambiguity raises questions about which timeout takes precedence, how to tune keep‑alive parameters without unintentionally extending connection lifetimes, and what telemetry is needed to detect ghost connections.
Which timeout—keep‑alive or connection‑level—wins when both are active? How should keep‑alive intervals be adjusted relative to mesh‑enforced idle timeouts to avoid ghost connections? What metrics or logging can reliably indicate that a connection has been kept alive solely by keep‑alive pings?
34775 reputation · 06 Apr 2022, 13:42 UTC
Neither timeout wins by precedence. gRPC keep-alive is an HTTP/2 application-layer mechanism; mesh/proxy connection idle timeout is a transport-layer timer. A keep-alive PING is bytes on the wire, so it resets the proxy's idle timer. The proxy closes only if no bytes are seen for its idle timeout. gRPC will consider the channel healthy if pings are acked, even if the mesh has already decided to terminate the TCP connection.
Because pings generate traffic, a connection can be kept alive solely by keep-alive traffic while carrying no RPC DATA. That is the ghost connection scenario. The interaction is additive, not a race with a winner: if keepalive interval < proxy idle timeout, the proxy never sees idle; if keepalive interval >= proxy idle timeout, the proxy may close first and gRPC will see a transport error.
Verification: force an idle connection and observe whether the proxy closes at its idle timeout or keepalive keeps it alive. Compare connection lifetime histograms from the proxy with gRPC client keepalive ping counters over a test idle period.
Which sidecar proxy and gRPC language/runtime version are in use. Older proxy versions and some runtimes treat HTTP/2 PING differently for idle accounting, and server-side keepalive enforcement defaults vary. That changes the exact safe margin and whether PINGs reliably reset the idle timer.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.