Article View

Scroll down to read the full article.

The Ghost in the /27: Diagnosing ETIMEDOUT on Idle HTTP/2 Connections in Kubernetes Egress

calendar_month November 29, 2026 |
Quick Summary: Frustrated by intermittent ETIMEDOUT on HTTP/2 from Kubernetes pods to external gRPC services? This SRE guide uncovers a niche network stack inter...
Alright, listen up. If you're seeing `ETIMEDOUT` on your outbound HTTP/2 (gRPC) connections, specifically after periods of *exactly* 30 seconds of idleness, and only from a particular subset of your Kubernetes pods, you've stumbled into one of those 'needle in a haystack' network demons. This isn't your garden variety network blip. This is a subtle, insidious interaction between your kernel's connection tracking, an aggressive external NAT gateway, and your application's keepalive settings.
A complex
A complex
Symptoms? Your applications might report intermittent connection failures, particularly on long-lived connections, or experience slow initial requests after an idle period. Retries might eventually succeed, masking the underlying issue as 'flakiness.' Developers will swear their code is fine, and honestly, they're probably right. This is deep in the trenches, where network engineers and SREs earn their gray hairs. This specific brand of hell typically manifests in environments where you have a mix of older network hardware, specific kernel versions, and CNI configurations. Here's a quick rundown of the environment sweet spot for this particular nightmare:
Component Version/Condition Notes
Kubernetes Cluster 1.20 - 1.23 Potentially older, or specific CNI configurations.
Kernel Version 4.19 - 5.4 Specific `netfilter` behaviors.
CNI Plugin Calico, Cilium (specific versions) Egress routing behavior plays a role.
Application Runtime Java 8/11 (gRPC clients) Default HTTP/2 PING intervals.
Source Pod IP Range `10.42.3.128/27` (example) The crucial trigger. Pods outside this range are unaffected.
External Service gRPC over HTTP/2 Target for the problematic connections.
Your first instinct might be `tcpdump`. You'll run it on the problematic pod, and guess what? The connection looks fine! The `FIN` or `RST` isn't coming from *your* end. But the `ETIMEDOUT` persists. This is where it gets tricky. The timeout isn't happening on the K8s node's `netfilter` table; it's happening at an *external* layer. **Diagnosis Steps:** 1. **Confirm the 30-second interval:** Set up a simple gRPC client that connects to the external service, sends one request, then idles for 20, 25, 30, 35 seconds before sending another. You'll likely see success at 25s, failure at 30s-31s, and success again after a reconnect. This is the smoking gun. 2. **Verify the /27 subnet:** Spin up identical pods, one with an IP in the problematic range, one outside it. Observe the behavior. If only the former fails, you've isolated the routing path. 3. **Check `netfilter` state on node:** On the K8s node hosting the problematic pod, use `conntrack -L` (if installed) or `cat /proc/net/nf_conntrack` to look for the established TCP connection. It'll likely still be there, showing a long `timeout` value, even when the application is failing. This tells you the node isn't dropping it. 4. **Egress Gateway Investigation:** This is the hard part. The problem lies with an external NAT gateway or firewall that this specific `/27` subnet's traffic is being routed through. This gateway has an aggressive, likely misconfigured, 30-second TCP idle timeout.

The Root Cause

Here’s the skinny: The application's HTTP/2 client (especially Java's gRPC implementation) has a default PING interval for idle connections that is often *greater* than 30 seconds (e.g., 60 seconds). Your Kubernetes node's `netfilter` connection tracking (`nf_conntrack_tcp_timeout_established`) is usually set to a generous 432000 seconds (5 days) by default, so it's not dropping the connection. However, the external NAT gateway, which *only* sees the traffic from that particular `/27` subnet, has its own, much shorter, *hard-coded* TCP idle timeout of exactly 30 seconds. This is often a bug in older hardware or a misconfiguration where a UDP timeout is applied to TCP. When the connection idles for 30 seconds, the NAT gateway unilaterally drops its state for that connection. The K8s node and the application still think the connection is alive. When the application tries to send a new request, the packet hits the NAT gateway, which has no state, silently drops the packet, and the client eventually times out with `ETIMEDOUT`. This specific routing for the `/27` subnet might be due to a specific network policy, an older egress router, or even a legacy VPN concentrator. Debugging these scenarios requires careful thought about how to scale distributed systems and maintain their resilience, especially in hyperscale environments. For more insights on architectural resilience, consider reading Scaling Petascale: Architecting Resilient Distributed Systems for Hyperscale.
A surgeon's hand with precise tools working on a tiny
A surgeon's hand with precise tools working on a tiny
**The Fix (aka, The Workaround that Becomes Permanent):** Since you likely can't instantly reconfigure or replace the external NAT gateway, your immediate, pragmatic solution is to ensure *your* end sends keepalive packets more frequently than the problematic gateway's timeout. You need to adjust the TCP keepalive parameters on the K8s host, or ideally, directly within your application if it supports it. For a cluster-wide fix (or node-specific if you can target only the affected nodes), you can adjust the `tcp_keepalive_time` parameter. This forces the kernel to send TCP keepalive probes after a specified idle period. ```bash sudo sysctl -w net.ipv4.tcp_keepalive_time=25 sudo sysctl -w net.ipv4.tcp_keepalive_intvl=3 sudo sysctl -w net.ipv4.tcp_keepalive_probes=5 ``` **Explanation of the fix:** * `net.ipv4.tcp_keepalive_time=25`: This sets the idle time (in seconds) before TCP starts sending keepalive probes. By setting it to 25 seconds, you guarantee that a probe is sent *before* the external NAT's 30-second timeout. This refreshes the NAT's connection state. * `net.ipv4.tcp_keepalive_intvl=3`: This sets the interval (in seconds) between successive keepalive probes. * `net.ipv4.tcp_keepalive_probes=5`: This sets the number of probes to send before concluding that the connection is dead. **Caveats:** * **Persistence:** These `sysctl` changes are not persistent across reboots. You'll need to add them to `/etc/sysctl.conf` or a file in `/etc/sysctl.d/` (e.g., `99-k8s-keepalive.conf`) to make them permanent. * **Impact:** This affects *all* TCP connections originating from that host. While generally safe, be aware of the minor increase in network traffic due to more frequent keepalives. In a hyperscale environment, even minor changes can have cascading effects, reinforcing why careful architectural planning, as discussed in Architecting for Billions: Scaling Distributed Systems in Hyperscale Environments, is crucial. * **Application-level tuning:** If your gRPC client library (e.g., Netty-based in Java) allows configuring HTTP/2 PING intervals, setting that to something like 20-25 seconds is often a cleaner, more targeted solution, as it applies only to the relevant application connections. This problem is obscure because it relies on a very specific set of conditions to align: a particular routing path, an old or misconfigured piece of network gear, and an application's default keepalive timing that happens to fall just outside the problematic timeout. Debugging these requires patience, a systematic approach, and a willingness to look beyond your immediate cluster boundaries. Good luck, and may your connections stay established.

Discussion

Comments

Read Next