Repository navigation
Description
What happens
When a backend that served a keep-alive request is stopped, the next request routed to the same cluster is written onto the back connection whose peer has already closed. sozu reads EOF and answers 502 Bad Gateway instead of retrying on a surviving backend.
Measured over 401 trials of test_issue_806 on main, with the assertions hardened: 25 failures, a 6.2% per-trial rate, reproducible on 25 of 25 runs.
The 502 body names the stopped backend:
backend1 aggregator: Some(SimpleAggregator { requests_received: 1, responses_sent: 1 })
backend2 aggregator: Some(SimpleAggregator { requests_received: 0, responses_sent: 0 })
reconnect: 651.979µs
the request after the backend stop was answered "HTTP/1.1 502 Bad Gateway", not "HTTP/1.1 200 OK"
with "backend_id": "cluster_0-0" — the backend that was stopped — and "parsing_phase": "Error".
Note reconnect: 651.979µs. This is a fast wrong answer, well inside any timing budget, so a test that only measures latency cannot see it.
Why it is not a test artefact
The mock backend closes gracefully: stop_and_get_aggregator drops the accepted streams on thread exit. This is the ordinary stale-keep-alive-upstream case that every reverse proxy has to handle — the peer FIN'd, sozu had not yet noticed, and the request was already written.
Cross-tabulated over the same 401 trials, the correspondence is exact with zero disagreement:
| backend2 aggregator | status | trials |
|---|---|---|
(1, 1) |
200 | 376 |
(0, 0) |
502 | 25 |
Where the retry is missing
CONN_RETRIES exists only in lib/src/tcp.rs. The HTTP path has no equivalent: a write onto a back connection that turns out to be closed is not retried against another backend from the load balancer.
Suggested resolution
On EOF from an upstream connection where no response bytes have yet been received, the request is idempotent with respect to the backend — nothing was observed, so re-issuing it on a fresh connection from the load balancer is safe. That is the standard boundary: retry only before any response byte arrives.
What I verified, and what I did not
Verified at source and by measurement: the 6.2% rate, the exact cross-tabulation, the stopped backend named in the 502 body, the graceful close in the mock, and the absence of CONN_RETRIES outside lib/src/tcp.rs.
Not verified: whether an existing retry path elsewhere in the HTTP state machine was intended to cover this and is simply not reached, and whether the right boundary is "no response bytes yet" or something narrower for non-idempotent methods.
Found while hardening test_issue_806 for #1427: the test previously asserted != State::Fail, which Undecided satisfied, and did not check the response status at all, so these 502s passed as successes.
Activity
fix(mux): replay an idempotent request on a fresh backend when its po…
fix(mux): replay an idempotent request on a fresh backend when its po…
fix(mux): replay an idempotent request on a fresh backend when its po…
fix(mux): replay an idempotent request on a fresh backend when its po…
fix(ci): bind and check a citation's bare `:NNN` continuation
fix(mux): replay an idempotent request on a fresh backend when its po…
fix(mux-h1): bound the stale-upstream replay captures and account for…
fix(mux-h1): bound the stale-upstream replay captures and account for…
fix(mux-h1): bound the stale-upstream replay captures and account for…
fix(parser): match the HTTP method token case-sensitively
fix(parser): match the HTTP method token case-sensitively (#1474)