Repository navigation
feat(agent): two-phase drain — DRAINING first, pool-close after delay - #152
Merged
Merged
Conversation
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]>
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]>
Owner
Author
|
Pushed Rationale (from review discussion): the phase-2 bound is not the 30s termination grace — it's the SIGTERM moment (end of preStop), since the pool close must land while the app still serves to beat the exit-GOAWAY race. The sleep preStop is machine-readable on the terminating Pod, so:
Workloads opt into generosity by sizing their own preStop — no mesh-side config. Unit-tested ( |
bpalermo
added a commit
that referenced
this pull request
Jun 12, 2026
… 10s for zero-loss rolls (#153) The two-phase drain (#152) scales the in-flight completion window with the workload's sleep preStop (window = sleep - 1s, capped 2s short of the termination grace). Update the guidance and example manifest from sleep 3 to sleep 10, with the measured results: sleep 10 -> 0 failed requests per roll under full load; sleep 3 (supported minimum) -> ~1 blip per pod. Document drain phase 2 in the termination sequence. Co-authored-by: Claude Opus 4.8 <[email protected]>
bpalermo
added a commit
that referenced
this pull request
Jun 12, 2026
…Phase 4) Service clusters no longer carry the per-client MeshReadyPath health check or IgnoreNewHostsUntilFirstHc: routability is EDS health (delegated liveness — endpoints register UNHEALTHY, the destination gateway vets them, promotion propagates in ~1s), and fast local failure detection is outlier detection, which is O(actual traffic) instead of O(clients x endpoints). Consecutive local-origin failures (3) catch the dead-pod-EDS-lag case; consecutive 5xx (5) catch a sick app; max_ejection_percent 50 keeps a local ejection wave from emptying a cluster EDS still believes healthy (panic threshold remains 0). Two-phase drain semantics (#152) are unchanged: DRAINING/UNHEALTHY still arrive via EDS and pool close still rides close_connections_on_host_health_failure. This retires the ~200M probes/sec mesh-wide HC term at the 3k-svc / 10k-node design point. Co-Authored-By: Claude Opus 4.8 <[email protected]>
bpalermo
added a commit
that referenced
this pull request
Jun 12, 2026
…Phase 4) (#161) Service clusters no longer carry the per-client MeshReadyPath health check or IgnoreNewHostsUntilFirstHc: routability is EDS health (delegated liveness — endpoints register UNHEALTHY, the destination gateway vets them, promotion propagates in ~1s), and fast local failure detection is outlier detection, which is O(actual traffic) instead of O(clients x endpoints). Consecutive local-origin failures (3) catch the dead-pod-EDS-lag case; consecutive 5xx (5) catch a sick app; max_ejection_percent 50 keeps a local ejection wave from emptying a cluster EDS still believes healthy (panic threshold remains 0). Two-phase drain semantics (#152) are unchanged: DRAINING/UNHEALTHY still arrive via EDS and pool close still rides close_connections_on_host_health_failure. This retires the ~200M probes/sec mesh-wide HC term at the 3k-svc / 10k-node design point. Co-authored-by: Claude Opus 4.8 <[email protected]>
This was referenced Sep 6, 2026
This was referenced Oct 1, 2026
bpalermo
added a commit
that referenced
this pull request
Oct 3, 2026
…THY from the Pod, so every replica closes pools before SIGTERM (#1144) The destination agent's second drain step (UNHEALTHY ~1 s before SIGTERM, #152) is a write the kubernetes backend ignores, so it reached only the registrar replica the agent is connected to; sources on other replicas kept their pools to the pod until its Ready condition dropped, after SIGTERM. The phase-2 moment is pod-visible: the deletion request time is deletionTimestamp - deletionGracePeriodSeconds, and the agent's delay is a function of the pod spec alone (sleep preStop - 1 s, floor 2 s, capped by the grace). That function moves to common/drain and both the agent and the backend call it; podHealth lists a terminating, still-Ready pod UNHEALTHY from drain.PoolCloseAt, and the pod informer arms one timer per pod that wakes the sync at that moment. No API writes, no RBAC change. e2e/drain-propagation.sh polls the source proxy's /clusters for the victim's health flags and reports mark -> source pool close per run, split same/cross replica. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo
added a commit
that referenced
this pull request
Oct 3, 2026
…THY from the Pod, so every replica closes pools before SIGTERM (#1144) (#1153) The destination agent's second drain step (UNHEALTHY ~1 s before SIGTERM, #152) is a write the kubernetes backend ignores, so it reached only the registrar replica the agent is connected to; sources on other replicas kept their pools to the pod until its Ready condition dropped, after SIGTERM. The phase-2 moment is pod-visible: the deletion request time is deletionTimestamp - deletionGracePeriodSeconds, and the agent's delay is a function of the pod spec alone (sleep preStop - 1 s, floor 2 s, capped by the grace). That function moves to common/drain and both the agent and the backend call it; podHealth lists a terminating, still-Ready pod UNHEALTHY from drain.PoolCloseAt, and the pod informer arms one timer per pod that wakes the sync at that moment. No API writes, no RBAC change. e2e/drain-propagation.sh polls the source proxy's /clusters for the victim's health flags and reports mark -> source pool close per run, split same/cross replica. Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr Co-authored-by: Claude Fable 5.1 <[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.
Goal
Eliminate the last ~6–7
code=000fails per svc roll without hard-closing active streams (directive: in-flight must complete).Why two phases
Both single-phase variants are instrumented and both leak:
Composed temporally, each phase covers the other's gap:
deletionTimestamp) → endpoint DRAINING (now mapped to EnvoyDRAINING): new selections stop within ~1s, in-flight completes.drainPoolCloseDelay) → termination watch re-registers UNHEALTHY:close_connections_on_host_health_failureshuts the by-then-idle pools while the app is still in its preStop window (workload-requirements: preStop ≥ 3s) — pre-empting the GOAWAY race.Safety
lifecycleMu) that the pod still exists and is still terminating — a CNI DEL that won the race is never resurrected (same pattern as the liveness loop).Validation
🤖 Generated with Claude Code