Skip to content

fix(quic): a twin request to a vanished destination fails 503 in <=10 s instead of hanging to the 15 s route timeout, and is never replayed (#1087) - #1101

Merged
bpalermo merged 6 commits into
mainfrom
fix/1087-quic-dead-endpoint-fail-fast
Oct 1, 2026
Merged

bpalermo merged 6 commits into
mainfrom
fix/1087-quic-dead-endpoint-fail-fast

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Closes #1087

What was happening

The source-side 504 UT lines from the 2026-10-01 TRIPLE (5 lines on svc-3@aether-test/default, each 14.89–15.00 s) have matching destination-reporter lines with the same x_request_id. Read-only VictoriaLogs query on aether_access_logs:

x_request_id source (start → result) destination (pod, result)
b59c3e97 w02 05:41:23.92 → 504 UT 15004 ms, 10.244.2.115 jcfxj (w05): 503 UF after 5005 ms (connect to 127.0.0.1:8080)
cfa6271b w02 05:41:24.04 → 504 UT 15004 ms jcfxj: code 0 after 3022 ms (stream gone)
976101aa w04 05:41:39.78 → 504 UT 14891 ms, 10.244.4.46 zv6zw (w02): 503 UF after 5002 ms
258c9a12 w04 05:41:39.91 → 504 UT 14975 ms zv6zw: code 0 after 4878 ms
5c0347ce w04 05:41:39.97 → 504 UT 14996 ms zv6zw: 503 UF after 5003 ms

So the requests were delivered over QUIC. upstream_peer_uri_san is populated on every source line, so the handshake was done. The destination agents had logged pod terminating: endpoint marked draining ahead of shutdown 3.4–3.8 s before each request: w05 at 05:41:20.14, w02 at 05:41:36.42. The pods' SPIRE entries were deleted at 05:41:27.1 and 05:41:44.1. In between, CNI DEL removed the pods' veths.

The destination proxy answered, or reset, at 3–5 s, but it wrote the answer into a pod netns that had no route out any more. The inbound QUIC listener is bound in the pod netns (NewInboundQUICListener, network_namespace_filepath). The source never received anything.

On the source side, nothing ran a timer shorter than the 15 s route timeout:

  • No PTO and no blackhole detection. The request was ACKed, so the source had nothing in flight. QUICHE (pin quiche 0.0.0-260922-7f07dc4) runs blackhole/path-degrading detection only while retransmittable packets are in flight and stops it in quiescence (quic/core/quic_connection.cc:3784-3797, 6356-6363). The 5-RTO detector (quic_connection.cc:6846-6864) is therefore never armed.
  • Idle timeout of 300 s. The twin set no quic_protocol_options. createPersistentQuicInfoForCluster converts the cluster's (empty) options (source/common/quic/client_connection_factory_impl.cc:36-38), and convertQuicConfig sets an idle timeout only when one is configured (source/common/quic/envoy_quic_utils.cc:413-425), so the client used QUICHE's kMaximumIdleTimeoutSecs of 600 s (quic_constants.h:161). The inbound listener's QuicProtocolOptions{} defaults to 300 s (source/common/quic/active_quic_listener.cc:324-329). The negotiated value is the minimum of the two (quic/core/quic_config.cc:1329-1337): 300 s.
  • First keep-alive PING at 15 s. The client keep-alive was QUICHE's kPingTimeoutSecs = 15 (quic_constants.h:170; quic_ping_manager.cc:98). Envoy only overrides it when connection_keepalive is set (source/common/quic/envoy_quic_client_session.cc:312-328).
  • --east-west-quic-idle-timeout (8 s, fix(quic): immediate drain + 8 s h3 twin idle so no source h3 connection outlives a hot-restart parent (#1054); skipParentStats default off now that #1060 fixes the deadlock #1063) does not apply. It is the HTTP pool's common_http_protocol_options.idle_timeout, which only counts streamless time, so it never fires with a stream open.
  • close_connections_on_host_health_failure does not close the connection either. Envoy closes pools only on active-HC failure or outlier ejection (source/common/upstream/cluster_manager_impl.cc:971-988). An EDS DRAINING update or removal only drains the pool, and in-flight streams keep waiting. The comment on NewServiceCluster saying "incl. the EDS drain mark" is inaccurate; see open risks.

The route timeout wins: 504 UT at 15 s. This is not specific to a restarting source agent. The kind red below reproduces it with the source agent frozen, and the soak shows it with the source agent up but the update arriving after the pick.

The h2 path has the same hole for an already-delivered request. The TCP request is ACKed, the response is lost, and no TCP keepalive or HTTP/2 PING is configured, so it also waits the full 15 s. There is no RST, because the netns is gone before anything can send one. I saw this once on kind when an agent swap left client-a on on_no_match (h2): 4 × 504 at 15.00 s. That run was discarded, and the harness now asserts that every measured request rode the twin. h2 is not changed here; see open risks.

The fix (twin clusters only)

config.Http3ProtocolOptions is used only by proxy.QUICClusterFrom. It now sets http3_protocol_options.quic_protocol_options:

quic_protocol_options:
  connection_keepalive: { max_interval: 1s }
  idle_network_timeout: 8s

How it works:

  • While a request stream is open (QuicSpdySession::ShouldKeepConnectionAlive, quic/core/http/quic_spdy_session.cc:1016-1020), the source sends a PING after 1 s of silence. QUICHE arms that alarm with 1 s granularity (quic_ping_manager.cc:37).
  • QuicIdleNetworkDetector closes the connection 8 s after the first ack-eliciting packet sent since the peer was last heard (quic/core/quic_idle_network_detector.cc:68-88). The unanswered PING also arms QUICHE's 5-RTO blackhole detector, which fires about 6.4 s after the PING; whichever comes first closes the connection.
  • Bound: interval + 1 s + idle ≤ 10 s after the destination's last packet (8.4–9.4 s measured on kind).
  • A live destination ACKs the PING however slow its application is, so slow requests are not touched. That is why this is transport liveness on the twin cluster, not a per_try_timeout / per_try_idle_timeout. Those would sit on the route the twin shares with its h2 base (the matcher plugin only swaps the cluster specifier), and they would cap slow-but-alive requests.

No replay, GET or POST:

  • The idle close resets open streams as ConnectionTermination: QUIC_NETWORK_IDLE_TIMEOUT with 1-RTT keys maps there (source/common/quic/envoy_quic_utils.cc:196-211, envoy_quic_client_stream.cc:470-480).
  • The mesh policy (connect-failure,refused-stream,reset-before-request,retriable-status-codes[503], outboundRetryPolicy) does not retry that. reset-before-request requires !upstream_request_started, which is set from first_upstream_tx_byte_sent_ (source/common/router/router.cc:1650-1653). Connect-failure only covers Local/RemoteConnectionFailure/ConnectionTimeout. A 503 response is not a reset (source/common/router/retry_state_impl.cc:433-490).
  • A non-idempotent POST fails fast with 503 and is never retried. So does a GET: we do not try to guess idempotency, because retriable_request_headers would scope the whole policy.
  • New requests to the dead endpoint fail the QUIC handshake within the cluster's 2 s connect_timeout (max_time_before_crypto_handshake, client_connection_factory_impl.cc:39-44). That is a connect failure, so they are retried on another endpoint with previous_hosts, as before.

Why 8 s and not 4 s (review change, #1093). The first revision used 4 s. #1093 (PR #1100) shows talos-main has node-local Envoy worker stalls: requests delayed 1–3.3 s, episodes of 5–7 s, including outside rolls. An idle deadline cannot tell a dead peer from one that is simply not being scheduled.

  • (a) Destination stall. A destination worker stalled for at least the idle timeout cannot ACK the PINGs. Every in-flight twin request to it would then fail 503 where today it completes late.
  • (b) Source stall, answered from source.
    • Safe when the peer's packets are queued in the socket. libevent activates fd events (event.c:2072, evsel->dispatch) before expired timers (event.c:2091, timeout_process), and Envoy sets no event priorities, so both sit in one FIFO active queue. EnvoyQuicClientConnection::onFileEvent reads the socket first (envoy_quic_client_connection.cc:319-364). Envoy stamps each packet with the time it is read (source/common/network/utility.cc:599, :674), not when it arrived, so OnPacketReceived pushes the deadline past now. EnvoyQuicAlarm::UpdateImpl → enableHRTimer → event_add then removes the stale timer activation from the active list (event.c:2796-2810).
    • Not safe when nothing is queued. Example: a request to a live but slow, silent application whose last ACK predates the stall. QuicIdleNetworkDetector::OnAlarm calls OnIdleNetworkDetected with no deadline re-check (quic_idle_network_detector.cc:28-30), and neither do QuicAlarm::Fire (quic_alarm.cc:82-93) or EnvoyQuicAlarm's callback (envoy_quic_alarm.cc:11). Such a request would be idled out spuriously.
  • Decision. The idle timeout must exceed the longest expected stall. The soak's failure count does not change with any value: those requests were delivered, so they are not retryable. This only shortens the hang, and must not buy that with new 503s during stalls. 8 s, equal to the pool idle (--east-west-quic-idle-timeout), so idle pairs pay no extra handshake. The constant's comment says to tighten it once proxy: a multi-second node-local stall at the parent's 'closing and draining listeners' during some hot-restart handoffs (1 liveness timeout in the 2026-10-01 soak, not #1085) #1093 is fixed. The unit test and the envoy_validate test both assert idle ≥ 8 s and bound ≤ 10 s.

Cost: the idle timeout is negotiated as the minimum on both ends, so an idle twin connection also closes after 8 s at the transport level, which matches the pool idle. A flag value above 8 s no longer lengthens reuse. The client's deadline is always earlier than the server's, because the server last heard the client's ACK of its final packet, so the client never sends into a connection the server has already closed. Docs updated: docs/configuration.md, docs/runbook.md (new #1087 section), flag help. No chart change.

Evidence

//test/envoy_validate — new test TestQUICUpstreamsDetectADeadPeer runs over the fixture bytes envoy --mode validate accepts. It asserts:

Seen red on main (assertion, not compile):

--- FAIL: TestQUICUpstreamsDetectADeadPeer
    quic:echo.demo.mesh.local@demo/source-a: no quic_protocol_options: the twin has no dead-peer detection (QUICHE idle default, 15 s keepalive), so a request to a vanished destination hangs to the route timeout
    quic:echo.demo.mesh.local@demo/source-b: (same)

Green on the branch. The existing TestEnvoyValidate also validates the fixture, which proves Envoy accepts the new options. A unit test, TestHttp3ProtocolOptionsDetectADeadPeer, pins the constants and the bound.

kind red → green — new harness e2e/eastwest-quic-deadpeer.sh (cluster aether-1087). It reuses the EWQ_WORKER=1 bring-up of e2e/eastwest-quic.sh, which gains EWQ_IMAGE_TAG so concurrent builds cannot swap :latest images.

Setup:

  • quic-a at 2 replicas on the worker, client-a on the control plane.
  • The source node's agent is frozen (SIGSTOP), so its EDS is stale, exactly like an agent that is away.
  • The victim's host veth is deleted (the CNI-DEL half that matters), then the pod is deleted with no preStop.
  • Before each leg the harness asserts that every measured request rode the twin, so the run measures HTTP/3, not h2.

Each arm ran on a fresh cluster. Agents: main 75caf0f vs branch e86ed62 (8 s), checked via the image revision label. The 4 s revision 3ec489b measured 5.0 s for leg A and a 6.01 s max for leg B. The twin's options were read from the source node's config dump: null on red, {"connection_keepalive":{"max_interval":"1s"},"idle_network_timeout":"8s"} on green.

leg red (main) green (this PR)
A: 2 GET + 2 POST in flight to the victim (10 s handler, network cut 2 s in) 4 × 504 at 15.002–15.003 s 4 × 503 at 9.41 s (a second run: 8.41 s), bound asserted ≤ 11.5 s
B: 4 GET loops + 1 slow POST/s, 15 s, cut 3 s in 159 req: 4 GET + 6 POST 503 at 6.41–12.43 s (QUICHE 5-RTO blackhole once a new request hits the dead connection), max 12.43 s 158 req: 4 GET + 2 POST 503 at 6.41–9.41 s, max 9.41 s, 0 × 504
N: every request id at most once across all quic-a app logs (victim streamed before it died) and every 200 accounted for pass (152 ids) pass (A 4 ids, B 153 ids): no replay

The first red run with the original harness had leg B 504 × 1 at 15.00 s (the POST in flight at the cut) and 503s at 6.41 s; same shape. Leg B also shows why the continuous scenario alone gives ~6.4 s on main rather than 15 s: a request sent onto the dead connection arms the blackhole detector. The 15 s hang needs a delivered request with nothing sent after it, which is leg A and the soak.

Commands:

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

Checks run

  • bazel test for //agent/internal/xds/{config,proxy,cache}:all, //agent/internal/cmd:all and //test/envoy_validate:all: all pass.
  • --config=race on //agent/internal/xds/config:all and //agent/internal/cmd:all: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.

Open risks / follow-ups (not in this PR)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits October 1, 2026 12:05
…worker stalls (#1087)

A 4 s idle deadline sits inside the 5-7 s node-local Envoy worker stalls
of #1093: a stalled destination cannot ACK the keepalive PINGs, and a
stalled source wakes with an expired idle alarm that QuicIdleNetworkDetector
fires without re-checking when nothing is queued (a request to a slow,
silent application). 8 s equals the pool idle, so no extra handshakes;
the dead-peer bound becomes ~10 s. Tighten once #1093 is fixed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo bpalermo changed the title fix(quic): a twin request to a vanished destination fails 503 in ~5 s instead of hanging to the 15 s route timeout, and is never replayed (#1087) fix(quic): a twin request to a vanished destination fails 503 in <=10 s instead of hanging to the 15 s route timeout, and is never replayed (#1087) Oct 1, 2026
@bpalermo
bpalermo merged commit fe006e5 into main Oct 1, 2026
36 of 38 checks passed
@bpalermo
bpalermo deleted the fix/1087-quic-dead-endpoint-fail-fast branch October 1, 2026 16:44
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