Skip to content

fix(xds): an h2 mesh request to a vanished endpoint fails 503 in <=~9 s instead of hanging to the 15 s route timeout, and is never replayed (#1104) - #1113

Merged
bpalermo merged 3 commits into
mainfrom
fix/1104-h2-dead-endpoint-keepalive
Oct 1, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/1104-h2-dead-endpoint-keepalive

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1104

What was happening

This is the h2 version of #1087. The h2 mesh clusters configured neither TCP keepalive nor an HTTP/2 PING. Take a request that the destination proxy had already received (TCP-ACKed) when its pod's veth was deleted:

  • The node-shared destination proxy keeps its inbound sockets in the dead pod netns. Its answer, and any FIN or RST, cannot leave.
  • The source has no unacked bytes, so no TCP retransmission timer runs.
  • Nothing else probes the connection, so the request waits for the 15 s route timeout and fails with 504 UT.

Since QUIC became unconditional, h2 carries three kinds of traffic: the GAMMA weighted split (by design, #961), waypointed (cross-cluster) traffic, and the edge→mesh hop.

Which builders have the hole. All three paths go through proxy.NewServiceCluster:

  • the default, per-port and alias clusters (cache/cluster.go);
  • the edge's mesh clusters (same cache; cache/mtls.go only swaps in the edge transport socket);
  • the waypoint path, where the source dials its own NewServiceCluster end to end.

ew_ingress_* is a raw tcp_proxy forwarder. The source's end-to-end PING passes through it, so the source side covers it. When the source closes on keepalive timeout, the tunnel's downstream closes and tcp_proxy tears down its upstream.

edge_k8s_* is HTTP/1.1 cleartext to non-mesh Services, so a PING is not possible there. Its exposure is also different: a non-mesh app closes its own sockets when it exits, before the sandbox network is torn down. It is out of scope; see risks.

The fix

config.MeshHttp2ProtocolOptions() is Http2ProtocolOptions() plus:

http2_protocol_options:
  connection_keepalive: { interval: 1s, interval_jitter: {value: 15}, timeout: 8s }

It is used only by NewServiceCluster. The constants MeshH2KeepaliveInterval, MeshH2KeepaliveTimeout and MeshH2KeepaliveJitterPercent sit next to QUICTwinKeepaliveInterval/QUICTwinNetworkIdleTimeout, with the same "tighten once #1093 is fixed" note.

Envoy semantics at the pin (726d7ac, source/common/http/http2/codec_impl.cc):

  • PINGs run on every connection, idle or not. The send timer is armed in the constructor and re-armed only by the PING ACK, at interval + random % (jitter% × interval) (:1011-1027, onKeepaliveResponse :1058-1071).
  • connection_idle_interval is a different knob. It sends a PING ahead of newStream on an idle connection (:2420-2431). It is not set here.
  • The timeout starts when the PING is sent (sendKeepalive :1036-1056). Any received frame pushes it out (:1216-1217), so a peer that is busy streaming a response is never cut off.
  • On expiry the connection is closed NoFlush and keepalive_timeout is incremented (:1073-1079).
  • Bound: 1.15 s + 8 s ≤ ~9.2 s after the peer's last frame.
  • The application never sees the PING. The ACK comes from the destination proxy's h2 codec, so a slow application is untouched. The kind control shows this: a 10 s handler on the live backend answers 200.
  • Idle pools are not kept alive. The pool idle timer (CodecClient) follows streams only (codec_client.cc enable/disableIdleTimer), so PINGs do not hold an idle connection open past UpstreamIdleTimeout.

Not on Http2ProtocolOptions(). That function is also used for the app hop (NewAppCluster http2), authz, xDS and collector clusters. Their h2 peer is not an aether proxy, and a gRPC server answers a PING every second with GOAWAY too_many_pings. The unit test, the proxy test and envoy_validate all assert that those clusters carry no keepalive.

No replay, GET or POST:

  • The keepalive close is a LocalClose on a connected client. CodecClient::onEvent resets every active stream with ConnectionTermination (codec_client.cc:124-137).
  • wouldRetryFromReset (retry_state_impl.cc:433-490) does not retry it under the mesh policy (connect-failure,refused-stream,reset-before-request,retriable-status-codes[503]):
    • connect-failure only covers Local/RemoteConnectionFailure and ConnectionTimeout;
    • reset-before-request needs !upstream_request_started, which is set from first_upstream_tx_byte_sent_ (router.cc:1650-1653);
    • no reset/5xx is configured.
  • GAMMA projection adds no retry policy. The edge routes use the same outboundRetryPolicy.
  • envoy_validate asserts this on every inline route onto an h2 mesh cluster: only those four conditions, and no per-try timeout.

Why 8 s (#1093). This is the same budget as the twins, for the same reason.

  • Destination stall (the risk that remains). A destination worker stalled for ≥ 8 s cannot ACK, so in-flight h2 requests to it would fail where today they complete late.
  • Source stall (safe for h2, unlike QUIC's silent-app case). A live peer ACKs within an RTT, so the ACK is already queued when the stalled worker wakes. libevent runs fd events before expired timers (event.c:2072 before :2091), and the read disables the timer, which removes its stale activation (event.c:2796-2810).

Comment fixes. The NewServiceCluster comment now says close_connections_on_host_health_failure fires only on active-HC failure (none is configured here) or outlier ejection (cluster_manager_impl.cc:971-988). An EDS removal only drains the host's pools (removeHosts → drainConnPools, :1954-1957), and in-flight streams keep waiting. I also fixed the circuit-breaker comment's "pool-close at drain-mark" and the matching assertion message in TestServiceClusterDrainPoolClose.

Evidence

//test/envoy_validate TestH2MeshClustersDetectADeadPeer.

  • It runs over the fixture bytes envoy --mode validate accepts, so TestEnvoyValidate also proves Envoy accepts the keepalive on every shape.
  • Scope is structural: every cluster with explicit h2 and an upstream TLS context. That is 14 h2 mesh clusters across every bootstrap: node plain/per-source/waypoint, cleartext, uds, capture, capture route-target, tcproute, edge, and the QUIC fixture's h2 base and alias.
  • It also checks the 6 inline routes onto those clusters.
  • Fixture change. The fixture's hand-built mesh clusters used to carry config.Http2ProtocolOptions(), which hid this. They now take their protocol options from proxy.NewServiceCluster itself (meshClusterProtocolOptions()).

Seen red on main with the test files applied to main's production code: an assertion failure, not a compile error.

--- FAIL: TestH2MeshClustersDetectADeadPeer
    node: waypoint-echo.mesh.local: no http2_protocol_options.connection_keepalive: a request delivered to an endpoint whose network then vanished gets no RST and hangs to the 15 s route timeout
    node: echo.mesh.local: (same) ... edge: echo.mesh.local ... quic_outbound: echo.demo.mesh.local:18081 ...   (14 of 14)

It is green on the branch.

Unit tests.

  • config.TestMeshHttp2ProtocolOptionsDetectADeadPeer pins the constants and the bound: ≤ 10 s, timeout ≥ 8 s, and equal to QUICTwinNetworkIdleTimeout. It also asserts that plain Http2ProtocolOptions has no PING.
  • proxy.TestServiceClusterH2PingLiveness checks that the default and per-port NewServiceCluster carry the keepalive, and that NewAppCluster(h2) and the passthrough do not.

kind, red then green (e2e/eastwest-quic-deadpeer.sh verify-h2, cluster aether-1104).

Setup:

  • The h2 path is forced through the suite's weighted GAMMA canary: gamma-a 50 / gamma-b 50, one replica each, on the worker.
  • Each leg asserts that every measured request rode an h2 cluster and that the quic: twins moved by +0.
  • The source agent is frozen, the victim's veth is deleted, and then the pod is deleted.
  • A pin cannot ride a split, so the split picks the backend. About half the requests land on the victim. The rest land on gamma-b, which is alive and slower than the 8 s timeout.

Arms:

  • Red agent: main's production code. Green agent: this branch.
  • Both arms ran on one cluster, switched with swap-agent.
  • The source Envoy's config_dump shows connection_keepalive as null on red and {"interval":"1s","interval_jitter":{"value":15},"timeout":"8s"} on green, on all six gamma clusters (default, :18081, :8080).
leg red (main) green (this PR), 2 runs
A2: 12 in flight (GET/POST alternating, 10 s handler), cut 2 s in victim: 5 × 504 at 15.003–15.004 s (an earlier run: 7 × 504 at 15.00 s); gamma-b: 7 × 200 at 10.0 s victim: 8 × 503 at 10.11–10.95 s and 8 × 503 at 10.12–10.78 s from request start, i.e. 8.1–8.95 s after the cut; gamma-b: 4 × 200 at 10.0 s each run (live and slow, not cut)
B2: 4 GET loops + 1 slow POST/s for 15 s, cut 3 s in 80 req: 12 × 504 at 15.00 s, max 15.003 s 85 / 89 req: 16 × 503 each, max 11.33 / 11.25 s, 0 × 504
N: every request id at most once across the gamma-a and gamma-b app logs, every 200 accounted for pass pass (A2 12 ids, B2 70 / 74 ids): no replay

Source stats after green: cluster.aether-test/gamma-a.http2.keepalive_timeout: 32 and upstream_cx_destroy_local_with_active_rq: 13. The upstream_rq_retry count comes from connect-failure retries of new requests to the dead host; N shows that none of them was a replay.

Note: the first red run reported A2 and N as expected, but its B2 assertion "≥ 20 requests rode h2" was too tight once requests stall behind the hang. It is now ≥ 10; twins must still be +0. Every later run passed.

Commands:

EWQ_CLUSTER=aether-1104 EWQ_IMAGE_TAG=<tag> EWQ_SKIP_BUILD=1 e2e/eastwest-quic-deadpeer.sh up
EWQ_CLUSTER=aether-1104 DP_EXPECT=red|green e2e/eastwest-quic-deadpeer.sh verify-h2

Checks run

  • bazel test for //agent/internal/xds/..., //agent/internal/edge/..., //test/envoy_validate:all and //test/mtlspool:all (real Envoy over NewServiceCluster, 66 s): all pass.
  • --config=race on //agent/internal/xds/config:all and //agent/internal/xds/proxy:all: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.

No chart change. Docs: docs/runbook.md has a new #1104 section, and the #1087 section now points to it.

Risks

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits October 1, 2026 14:33
… s instead of hanging to the 15 s route timeout, and is never replayed (#1104)

The h2 service clusters (NewServiceCluster: GAMMA weighted split, waypointed
and edge->mesh traffic) configured neither TCP keepalive nor an HTTP/2 PING,
so a request delivered to an endpoint whose pod veth then vanished got no FIN
or RST and waited for the route timeout (504 UT at 15 s).

Every h2 mesh cluster now carries http2_protocol_options.connection_keepalive
{interval 1s, jitter 15%, timeout 8s} (config.MeshHttp2ProtocolOptions), the
same 8 s budget as the QUIC twins (#1087) for the same #1093 reason. The
keepalive close resets the stream as ConnectionTermination, which the mesh
retry policy does not retry. Clusters whose h2 peer is not an aether proxy
(app hop, authz, xDS, collector, passthrough) keep plain h2 options.

Also corrects the NewServiceCluster comment: close_connections_on_host_health_failure
fires only on active-HC failure or outlier ejection, never on the EDS drain mark.

Proof: //test/envoy_validate TestH2MeshClustersDetectADeadPeer (14 h2 mesh
clusters across every fixture, red on main), unit tests pinning the constants
and bound, and e2e/eastwest-quic-deadpeer.sh verify-h2 on kind (red: 504 at
15.00 s; green: 503 at 10.1-10.95 s from request start, cut at 2 s; no replay).

Closes #1104

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 8280612 into main Oct 1, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1104-h2-dead-endpoint-keepalive branch October 1, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant