Repository navigation
[3/N] [HAProxy stability] - option redispatch 1 + retry-on conn-failure - #63622
abrarsheikh merged 5 commits into
Conversation
56b3684 to
21d7341
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces HAProxy retry logic by adding option redispatch and retry-on conn-failure 503 to the configuration templates, allowing requests to be retried on different slots during connection failures or 503 errors. Corresponding updates were made to the HAProxy API and HTTP route tests to reflect these configuration changes and handle potential 503 status codes. I have no feedback to provide as there were no review comments.
7465478 to
9f193d2
Compare
9f193d2 to
be13789
Compare
Under autoscaling churn, the first connect attempt to a slot can hit a
replica that is briefly down (just-removed, mid-restart, scaling-up
slot not yet accepting). Today HAProxy returns the resulting 502/503
directly to the client even though a peer slot is up and ready.
Add two defaults-level directives so requests transparently retry to a
healthy peer:
- `option redispatch 1` — every retry picks a different slot, not
just the last one (HAProxy default). With `retries 3`, a dead slot
no longer burns 3 same-slot attempts before failing over.
- `retry-on conn-failure 503` — restricts retries to cases that
cannot have leaked a partial body to the client: TCP connect
failure (no bytes sent) and a 503 from the backend (HAProxy hasn't
begun forwarding a real response yet).
`option redispatch` was previously set only on the
`*-via-ingress-request-router` backend; the primary routing path had
no retry semantics, which is why churn-class 5xx surfaced to clients.
Also add `errorfile 503` to the existing normalization block. After
enabling `retry-on 503`, exhausted retries surface HAProxy's own 503
to the client; routing it through the existing 500.http file keeps
the Serve contract of "upstream unavailable looks like a 500."
Co-Authored-By: Claude Opus 4.7 <[email protected]>
be13789 to
1e98755
Compare
eicherseiji
left a comment
There was a problem hiding this comment.
Thanks @harshit-anyscale! Two comments:
- It looks like this will retry legitimate 503s due to
max_queued_requestsin addition to the autoscaling churn. In #63308 retries for churn were retried viaconn-failure empty-response. Is there a reason we can't take the same approach here? - The
*-via-ingress-request-routerretry path now diverges from the default path. Can these be unified?
`retry-on conn-failure 503` also retried Serve's deliberate 503s (max_queued_requests backpressure, DeploymentUnavailable), defeating backpressure and amplifying load under overload — with no churn benefit: churn surfaces as a connect failure (already covered by conn-failure), and HAProxy's own no-server 503 isn't matched by retry-on <status> anyway. Also intentionally not adding empty-response: it retries a request that already reached the replica, which can double-execute a non-idempotent request, and Serve hosts arbitrary user endpoints we can't assume are idempotent. conn-failure is the only condition where nothing was sent, so it's safe to replay for any method. errorfile 503 stays — HAProxy still emits its own 503 when conn-failure retries exhaust, and that normalizes to 500. Addresses review feedback on ray-project#63622 (eicherseiji). Co-Authored-By: Claude Opus 4.7 <[email protected]>
The default path's retry config was hardcoded while the *-via-ingress-request-router backend had its own option redispatch + ingress_retry_on/retries — two retry policies that diverged. Define one policy in the defaults block, inherited by every backend: - RAY_SERVE_HAPROXY_RETRY_ON (default "conn-failure") -> retry-on - RAY_SERVE_HAPROXY_RETRIES (default None -> HAProxy's implicit 3) The ingress backend no longer defines retry-on / retries / redispatch of its own; it inherits the defaults block (so a DOWN/slow pinned server still falls through to a peer). RAY_SERVE_HAPROXY_INGRESS_RETRY_ON / INGRESS_RETRIES are kept but default to the global values, so there is a single retry policy everywhere; timeout server stays as the only per-ingress override. Default rendering is unchanged (retry_on defaults to conn-failure, retries renders nothing), so the golden config test is byte-identical apart from the reworded comment. Addresses review feedback on ray-project#63622 (eicherseiji, point 2). Co-Authored-By: Claude Opus 4.7 <[email protected]>
9340679 to
b467eea
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit b467eea. Configure here.
…gle reload (#63623) ## Summary Carved out of #63308 so the coalescing change can land independently of the stderr-redirect (#63621) and redispatch (#63622) changes in that PR. Under autoscaling churn the controller's `target_groups` broadcast fires frequently — its replica set changes on essentially every reconcile that adds or removes a replica — and each broadcast triggers its own config regeneration and graceful reload via `-sf`. Both `target_groups` and `fallback_targets` are emitted from the same control-loop step, so when both change in one ~100 ms tick they reach the proxy microseconds apart and (pre-coalescing) cause two back-to-back reloads. Both broadcasts are already change-gated on the controller (`broadcast_*_if_changed`), so this PR collapses genuine consecutive / same-tick changes into one reload — it is not suppressing redundant no-op broadcasts. (`fallback_targets` in particular is near-static in steady state; it only changes when the fallback proxy's health flips or its actor is replaced.) This PR collapses adjacent broadcasts into a single reload: - `HAProxyManager` keeps two pieces of state: `_update_pending: bool` and `_coalesce_task: Optional[asyncio.Task]`. - Each incoming broadcast sets `_update_pending = True` and arms (or re-arms) a single sleeping coalesce task. - The task sleeps for `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (default 100 ms; set to 0 to disable) and then runs one `_update_haproxy_backends()` call against whatever the latest state is. - Broadcasts arriving inside the window are absorbed — they flip the dirty flag, but the task is already armed, so no second reload is scheduled. **Failure handling.** If the apply fails, the task re-arms itself and retries on the next tick. After 3 consecutive failures it stops re-arming and waits for the next broadcast to trigger fresh state — this prevents busy-spinning against a persistent error (e.g. HAProxy crashed and is stuck restarting) while still recovering automatically once a new broadcast lands. **Knob.** `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (env var, float seconds). 100 ms by default — small enough that the worst-case extra latency from a single broadcast is bounded, large enough to catch the common back-to-back pattern observed during scale events. Set to `0` to opt out entirely. --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
…re (ray-project#63622) ## Summary Carved out of ray-project#63308 so the retry/redispatch fix can land independently of the stderr-redirect (ray-project#63621) and broadcast-coalescing changes in that PR. Under autoscaling churn, the first connect attempt to a slot can hit a replica that's briefly down (just-removed, mid-restart, scaling-up slot not yet accepting). HAProxy returns the resulting 5xx directly to the client even though a peer slot is up and ready. This PR adds three defaults-level directives so churn-class failures are retried transparently and normalized consistently: - **`option redispatch 1`** — every retry picks a *different* slot, not just the last one (HAProxy's default). With default `retries 3`, a bare `option redispatch` would send `A, A, A, B` against a dead slot; `redispatch 1` makes it `A, B, C, D` so a dead slot doesn't burn N attempts on itself. Previously redispatch was set only on the `*-via-ingress-request-router` backend; the primary routing path had no retry semantics, which is why churn-class 5xx surfaced to clients. - **`retry-on conn-failure`** — retries only TCP connect failures: nothing was sent to the replica, so the request is safe to replay for any method. We deliberately do **not** retry backend 503s (those are Serve's intentional `max_queued_requests` backpressure / `DeploymentUnavailable` responses — retrying them defeats backpressure and amplifies load), and do **not** add `empty-response` (the request already reached the replica, so replaying it could double-execute a non-idempotent endpoint, and Serve hosts arbitrary user code we can't assume is idempotent). HAProxy's own "no server" 503 isn't matched by `retry-on <status>` regardless. - **`errorfile 503`** — added alongside the existing `errorfile 502` / `errorfile 504`. When `conn-failure` retries are exhausted (all slots unreachable), HAProxy emits its *own* 503; routing it through the 500.http file preserves Serve's contract that upstream-unavailable looks like a 500. (This only rewrites HAProxy-generated 503s, not a backend's deliberate backpressure 503, which still reaches the client as 503.) Streaming responses where a partial body has already been written are explicitly **not** retried — neither directive triggers on `junk-response` / `response-timeout`. ### Changes from the original ray-project#63308 form - `retry-on conn-failure empty-response` → `retry-on conn-failure`. Dropped `empty-response`: it replays a request that already reached the replica, which can double-execute a non-idempotent endpoint (Serve runs arbitrary user code, so we can't assume idempotency). `conn-failure` alone covers the churn case (slot briefly down → connect fails) and is safe for any method. - `option redispatch` → `option redispatch 1`. The bare form only redispatches the final retry; `1` redispatches every retry. - Added `errorfile 503` to normalize HAProxy's own no-server / connect-exhaustion 503 to 500. ([Cursor review feedback](ray-project#63622 (comment))). --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
…gle reload (ray-project#63623) ## Summary Carved out of ray-project#63308 so the coalescing change can land independently of the stderr-redirect (ray-project#63621) and redispatch (ray-project#63622) changes in that PR. Under autoscaling churn the controller's `target_groups` broadcast fires frequently — its replica set changes on essentially every reconcile that adds or removes a replica — and each broadcast triggers its own config regeneration and graceful reload via `-sf`. Both `target_groups` and `fallback_targets` are emitted from the same control-loop step, so when both change in one ~100 ms tick they reach the proxy microseconds apart and (pre-coalescing) cause two back-to-back reloads. Both broadcasts are already change-gated on the controller (`broadcast_*_if_changed`), so this PR collapses genuine consecutive / same-tick changes into one reload — it is not suppressing redundant no-op broadcasts. (`fallback_targets` in particular is near-static in steady state; it only changes when the fallback proxy's health flips or its actor is replaced.) This PR collapses adjacent broadcasts into a single reload: - `HAProxyManager` keeps two pieces of state: `_update_pending: bool` and `_coalesce_task: Optional[asyncio.Task]`. - Each incoming broadcast sets `_update_pending = True` and arms (or re-arms) a single sleeping coalesce task. - The task sleeps for `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (default 100 ms; set to 0 to disable) and then runs one `_update_haproxy_backends()` call against whatever the latest state is. - Broadcasts arriving inside the window are absorbed — they flip the dirty flag, but the task is already armed, so no second reload is scheduled. **Failure handling.** If the apply fails, the task re-arms itself and retries on the next tick. After 3 consecutive failures it stops re-arming and waits for the next broadcast to trigger fresh state — this prevents busy-spinning against a persistent error (e.g. HAProxy crashed and is stuck restarting) while still recovering automatically once a new broadcast lands. **Knob.** `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (env var, float seconds). 100 ms by default — small enough that the worst-case extra latency from a single broadcast is bounded, large enough to catch the common back-to-back pattern observed during scale events. Set to `0` to opt out entirely. --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
…re (ray-project#63622) ## Summary Carved out of ray-project#63308 so the retry/redispatch fix can land independently of the stderr-redirect (ray-project#63621) and broadcast-coalescing changes in that PR. Under autoscaling churn, the first connect attempt to a slot can hit a replica that's briefly down (just-removed, mid-restart, scaling-up slot not yet accepting). HAProxy returns the resulting 5xx directly to the client even though a peer slot is up and ready. This PR adds three defaults-level directives so churn-class failures are retried transparently and normalized consistently: - **`option redispatch 1`** — every retry picks a *different* slot, not just the last one (HAProxy's default). With default `retries 3`, a bare `option redispatch` would send `A, A, A, B` against a dead slot; `redispatch 1` makes it `A, B, C, D` so a dead slot doesn't burn N attempts on itself. Previously redispatch was set only on the `*-via-ingress-request-router` backend; the primary routing path had no retry semantics, which is why churn-class 5xx surfaced to clients. - **`retry-on conn-failure`** — retries only TCP connect failures: nothing was sent to the replica, so the request is safe to replay for any method. We deliberately do **not** retry backend 503s (those are Serve's intentional `max_queued_requests` backpressure / `DeploymentUnavailable` responses — retrying them defeats backpressure and amplifies load), and do **not** add `empty-response` (the request already reached the replica, so replaying it could double-execute a non-idempotent endpoint, and Serve hosts arbitrary user code we can't assume is idempotent). HAProxy's own "no server" 503 isn't matched by `retry-on <status>` regardless. - **`errorfile 503`** — added alongside the existing `errorfile 502` / `errorfile 504`. When `conn-failure` retries are exhausted (all slots unreachable), HAProxy emits its *own* 503; routing it through the 500.http file preserves Serve's contract that upstream-unavailable looks like a 500. (This only rewrites HAProxy-generated 503s, not a backend's deliberate backpressure 503, which still reaches the client as 503.) Streaming responses where a partial body has already been written are explicitly **not** retried — neither directive triggers on `junk-response` / `response-timeout`. ### Changes from the original ray-project#63308 form - `retry-on conn-failure empty-response` → `retry-on conn-failure`. Dropped `empty-response`: it replays a request that already reached the replica, which can double-execute a non-idempotent endpoint (Serve runs arbitrary user code, so we can't assume idempotency). `conn-failure` alone covers the churn case (slot briefly down → connect fails) and is safe for any method. - `option redispatch` → `option redispatch 1`. The bare form only redispatches the final retry; `1` redispatches every retry. - Added `errorfile 503` to normalize HAProxy's own no-server / connect-exhaustion 503 to 500. ([Cursor review feedback](ray-project#63622 (comment))). --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
…gle reload (ray-project#63623) ## Summary Carved out of ray-project#63308 so the coalescing change can land independently of the stderr-redirect (ray-project#63621) and redispatch (ray-project#63622) changes in that PR. Under autoscaling churn the controller's `target_groups` broadcast fires frequently — its replica set changes on essentially every reconcile that adds or removes a replica — and each broadcast triggers its own config regeneration and graceful reload via `-sf`. Both `target_groups` and `fallback_targets` are emitted from the same control-loop step, so when both change in one ~100 ms tick they reach the proxy microseconds apart and (pre-coalescing) cause two back-to-back reloads. Both broadcasts are already change-gated on the controller (`broadcast_*_if_changed`), so this PR collapses genuine consecutive / same-tick changes into one reload — it is not suppressing redundant no-op broadcasts. (`fallback_targets` in particular is near-static in steady state; it only changes when the fallback proxy's health flips or its actor is replaced.) This PR collapses adjacent broadcasts into a single reload: - `HAProxyManager` keeps two pieces of state: `_update_pending: bool` and `_coalesce_task: Optional[asyncio.Task]`. - Each incoming broadcast sets `_update_pending = True` and arms (or re-arms) a single sleeping coalesce task. - The task sleeps for `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (default 100 ms; set to 0 to disable) and then runs one `_update_haproxy_backends()` call against whatever the latest state is. - Broadcasts arriving inside the window are absorbed — they flip the dirty flag, but the task is already armed, so no second reload is scheduled. **Failure handling.** If the apply fails, the task re-arms itself and retries on the next tick. After 3 consecutive failures it stops re-arming and waits for the next broadcast to trigger fresh state — this prevents busy-spinning against a persistent error (e.g. HAProxy crashed and is stuck restarting) while still recovering automatically once a new broadcast lands. **Knob.** `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (env var, float seconds). 100 ms by default — small enough that the worst-case extra latency from a single broadcast is bounded, large enough to catch the common back-to-back pattern observed during scale events. Set to `0` to opt out entirely. --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
…re (ray-project#63622) ## Summary Carved out of ray-project#63308 so the retry/redispatch fix can land independently of the stderr-redirect (ray-project#63621) and broadcast-coalescing changes in that PR. Under autoscaling churn, the first connect attempt to a slot can hit a replica that's briefly down (just-removed, mid-restart, scaling-up slot not yet accepting). HAProxy returns the resulting 5xx directly to the client even though a peer slot is up and ready. This PR adds three defaults-level directives so churn-class failures are retried transparently and normalized consistently: - **`option redispatch 1`** — every retry picks a *different* slot, not just the last one (HAProxy's default). With default `retries 3`, a bare `option redispatch` would send `A, A, A, B` against a dead slot; `redispatch 1` makes it `A, B, C, D` so a dead slot doesn't burn N attempts on itself. Previously redispatch was set only on the `*-via-ingress-request-router` backend; the primary routing path had no retry semantics, which is why churn-class 5xx surfaced to clients. - **`retry-on conn-failure`** — retries only TCP connect failures: nothing was sent to the replica, so the request is safe to replay for any method. We deliberately do **not** retry backend 503s (those are Serve's intentional `max_queued_requests` backpressure / `DeploymentUnavailable` responses — retrying them defeats backpressure and amplifies load), and do **not** add `empty-response` (the request already reached the replica, so replaying it could double-execute a non-idempotent endpoint, and Serve hosts arbitrary user code we can't assume is idempotent). HAProxy's own "no server" 503 isn't matched by `retry-on <status>` regardless. - **`errorfile 503`** — added alongside the existing `errorfile 502` / `errorfile 504`. When `conn-failure` retries are exhausted (all slots unreachable), HAProxy emits its *own* 503; routing it through the 500.http file preserves Serve's contract that upstream-unavailable looks like a 500. (This only rewrites HAProxy-generated 503s, not a backend's deliberate backpressure 503, which still reaches the client as 503.) Streaming responses where a partial body has already been written are explicitly **not** retried — neither directive triggers on `junk-response` / `response-timeout`. ### Changes from the original ray-project#63308 form - `retry-on conn-failure empty-response` → `retry-on conn-failure`. Dropped `empty-response`: it replays a request that already reached the replica, which can double-execute a non-idempotent endpoint (Serve runs arbitrary user code, so we can't assume idempotency). `conn-failure` alone covers the churn case (slot briefly down → connect fails) and is safe for any method. - `option redispatch` → `option redispatch 1`. The bare form only redispatches the final retry; `1` redispatches every retry. - Added `errorfile 503` to normalize HAProxy's own no-server / connect-exhaustion 503 to 500. ([Cursor review feedback](ray-project#63622 (comment))). --------- Co-authored-by: Claude Opus 4.7 <[email protected]> Signed-off-by: 400Ping <[email protected]>
…gle reload (ray-project#63623) ## Summary Carved out of ray-project#63308 so the coalescing change can land independently of the stderr-redirect (ray-project#63621) and redispatch (ray-project#63622) changes in that PR. Under autoscaling churn the controller's `target_groups` broadcast fires frequently — its replica set changes on essentially every reconcile that adds or removes a replica — and each broadcast triggers its own config regeneration and graceful reload via `-sf`. Both `target_groups` and `fallback_targets` are emitted from the same control-loop step, so when both change in one ~100 ms tick they reach the proxy microseconds apart and (pre-coalescing) cause two back-to-back reloads. Both broadcasts are already change-gated on the controller (`broadcast_*_if_changed`), so this PR collapses genuine consecutive / same-tick changes into one reload — it is not suppressing redundant no-op broadcasts. (`fallback_targets` in particular is near-static in steady state; it only changes when the fallback proxy's health flips or its actor is replaced.) This PR collapses adjacent broadcasts into a single reload: - `HAProxyManager` keeps two pieces of state: `_update_pending: bool` and `_coalesce_task: Optional[asyncio.Task]`. - Each incoming broadcast sets `_update_pending = True` and arms (or re-arms) a single sleeping coalesce task. - The task sleeps for `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (default 100 ms; set to 0 to disable) and then runs one `_update_haproxy_backends()` call against whatever the latest state is. - Broadcasts arriving inside the window are absorbed — they flip the dirty flag, but the task is already armed, so no second reload is scheduled. **Failure handling.** If the apply fails, the task re-arms itself and retries on the next tick. After 3 consecutive failures it stops re-arming and waits for the next broadcast to trigger fresh state — this prevents busy-spinning against a persistent error (e.g. HAProxy crashed and is stuck restarting) while still recovering automatically once a new broadcast lands. **Knob.** `RAY_SERVE_HAPROXY_BROADCAST_COALESCE_S` (env var, float seconds). 100 ms by default — small enough that the worst-case extra latency from a single broadcast is bounded, large enough to catch the common back-to-back pattern observed during scale events. Set to `0` to opt out entirely. --------- Co-authored-by: Claude Opus 4.7 <[email protected]> Signed-off-by: 400Ping <[email protected]>

Summary
Carved out of #63308 so the retry/redispatch fix can land independently of the stderr-redirect (#63621) and broadcast-coalescing changes in that PR.
Under autoscaling churn, the first connect attempt to a slot can hit a replica that's briefly down (just-removed, mid-restart, scaling-up slot not yet accepting). HAProxy returns the resulting 5xx directly to the client even though a peer slot is up and ready.
This PR adds three defaults-level directives so churn-class failures are retried transparently and normalized consistently:
option redispatch 1— every retry picks a different slot, not just the last one (HAProxy's default). With defaultretries 3, a bareoption redispatchwould sendA, A, A, Bagainst a dead slot;redispatch 1makes itA, B, C, Dso a dead slot doesn't burn N attempts on itself. Previously redispatch was set only on the*-via-ingress-request-routerbackend; the primary routing path had no retry semantics, which is why churn-class 5xx surfaced to clients.retry-on conn-failure— retries only TCP connect failures: nothing was sent to the replica, so the request is safe to replay for any method. We deliberately do not retry backend 503s (those are Serve's intentionalmax_queued_requestsbackpressure /DeploymentUnavailableresponses — retrying them defeats backpressure and amplifies load), and do not addempty-response(the request already reached the replica, so replaying it could double-execute a non-idempotent endpoint, and Serve hosts arbitrary user code we can't assume is idempotent). HAProxy's own "no server" 503 isn't matched byretry-on <status>regardless.errorfile 503— added alongside the existingerrorfile 502/errorfile 504. Whenconn-failureretries are exhausted (all slots unreachable), HAProxy emits its own 503; routing it through the 500.http file preserves Serve's contract that upstream-unavailable looks like a 500. (This only rewrites HAProxy-generated 503s, not a backend's deliberate backpressure 503, which still reaches the client as 503.)Streaming responses where a partial body has already been written are explicitly not retried — neither directive triggers on
junk-response/response-timeout.Changes from the original #63308 form
retry-on conn-failure empty-response→retry-on conn-failure. Droppedempty-response: it replays a request that already reached the replica, which can double-execute a non-idempotent endpoint (Serve runs arbitrary user code, so we can't assume idempotency).conn-failurealone covers the churn case (slot briefly down → connect fails) and is safe for any method.option redispatch→option redispatch 1. The bare form only redispatches the final retry;1redispatches every retry.errorfile 503to normalize HAProxy's own no-server / connect-exhaustion 503 to 500. (Cursor review feedback).