Repository navigation
fix(agent): close upstream pools at drain-mark — eliminates the P2 app-drain gap - #143
Merged
Merged
Conversation
…p-drain gap Instrumented two controlled svc rolls (2026-06-11) and pinned the residual ~3-7 fails per pod delete: the drain pipeline itself is fast and correct (deletionTimestamp -> EDS mark on every client in <800ms, zero fails in the propagation window), but Envoy's DRAINING health keeps established H2 pool connections OPEN. They sit idle through preStop and die at the app's shutdown GOAWAY — and streams the server had claimed but not yet answered at that instant fail non-retriably (upstream_rq_rx_reset=0 across all nodes: the app never broke a response; retry_success == retry_total: every retry that could fire succeeded; the fails were the GOAWAY last_stream_id race plus two retry_overflow rejections). Fix: report draining endpoints as UNHEALTHY instead of DRAINING and set close_connections_on_host_health_failure on the service clusters. Pools now close at drain-mark time (~t0+0.8s) while the app is healthy and the pools are idle; anything caught mid-transmit resets pre-request and retries successfully onto a live endpoint. The app-side preStop window is unchanged and still covers genuinely in-progress responses. Supporting changes on the service clusters: - healthy_panic_threshold: 0 — with drainers now counting as unhealthy, a heavy simultaneous roll could cross Envoy's default 50% panic threshold and spray traffic at known-unhealthy hosts; deterministic exclusion + per-request retries + the registry health pipeline are the mesh's answer, not panic spraying. - max_retries circuit breaker 3 -> 16 — the drain-time pool close briefly produces a burst of pre-request resets; the default breaker rejected retries under exactly that burst (retry_overflow observed). Validation plan: re-run the instrumented single-svc roll; expect 0 fails (first-pod-deleted rolls already showed 0 — the fix makes every pod look like the first). Also re-confirmed during instrumentation: zero 404s under churn (the #142 retention guard holding). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This was referenced Jun 11, 2026
bpalermo
added a commit
that referenced
this pull request
Jun 12, 2026
…#152) * feat(agent): two-phase drain — DRAINING first, pool-close after delay Never hard-close active streams on a graceful pod exit (directive 2026-06-11): in-flight requests must complete. Both single-phase drain variants were instrumented and both leak: - Envoy DRAINING alone leaves idle H2 pool connections open until the app's exit GOAWAY/RST, stranding claimed-but-unanswered streams non-retriably (~3-7 per pod delete). - UNHEALTHY + close_connections_on_host_health_failure (#143) closes pools at drain-mark but cuts streams active at that instant (~6-7 per roll, all code=000 — the current residue). Compose them temporally instead: - Phase 1 (deletionTimestamp): the endpoint goes DRAINING and now maps to Envoy DRAINING — excluded from new selections within ~1s of propagation, established streams run to completion. - Phase 2 (t0 + drainPoolCloseDelay 2s): the termination watch re-registers the endpoint UNHEALTHY; clients' close_connections_on_host_health_failure shuts the by-then-idle pools while the app is still inside its preStop window — ahead of the exit-GOAWAY race phase 1 alone would lose. Phase 2 re-checks pod existence + terminating under lifecycleMu so a CNI DEL that won the race is never resurrected; ctx cancellation aborts it. Delay is a server field (overridable in tests; production default 2s, sized to land inside the workload-requirements preStop >= 3s window). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(agent): scale the drain window with the workload's preStop sleep The phase-2 bound is not the 30s termination grace — it is the moment the app receives SIGTERM (end of preStop), because the pool close must land while the app still serves to pre-empt the exit-GOAWAY race. A sleep preStop is machine-readable from the terminating Pod object, so derive the delay per pod: close 1s before SIGTERM, capped 2s short of the deletion grace (kubelet hard kill). preStop sleep 15 buys in-flight requests a 14s window; the e2e workloads' sleep 3 keeps today's 2s; exec hooks and hookless pods keep the conservative floor. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last open mesh bug. Two instrumented svc-1 rolls (per-fail timestamps correlated against each old pod's
deletionTimestamp, plus Envoy reset/retry stat deltas) pinned the residual ~3–7 fails per pod delete.What the data showed
upstream_rq_rx_reset = 0everywhere — the app never broke a response.retry_success == retry_total— every retry that could fire succeeded.Mechanism: Envoy's
DRAININGhealth excludes a host from new picks but deliberately keeps established H2 pool connections open. They idle through preStop and die at the app's shutdown GOAWAY — and streams the server had claimed but not yet answered at that instant fail non-retriably (last_stream_idrace). Plus tworetry_overflowrejections from the default 3-concurrent retry breaker.The fix
UNHEALTHY(notDRAINING) +close_connections_on_host_health_failure: trueon service clusters: pools close at drain-mark time (~t0+0.8s) while the app is healthy and the pools are idle; anything caught mid-transmit resets pre-request and retries successfully onto a live endpoint. Envoy's connection-level "drain gradually" semantics are redundant here — the mesh already does the gradual part at the EDS level with the app serving through preStop.healthy_panic_threshold: 0: with drainers counting as unhealthy, a heavy simultaneous roll could cross the default 50% panic threshold and spray traffic at known-unhealthy hosts. Deterministic exclusion + per-request retries + the registry health pipeline are the mesh's answer (same call Istio makes).max_retriesbreaker 3 → 16: the drain-time pool close produces a brief burst of pre-request resets; the default breaker rejected retries under exactly that burst (observedretry_overflow).Validation
🤖 Generated with Claude Code