Repository navigation
Closed
Description
Summary
When a backend accepts no connection (blackholed: SYN dropped, or accept queue full), the backend connect timer fires before any response byte and Sōzu answers 504 Gateway Timeout instead of trying another backend. The failure is never counted, so the load balancer keeps sending requests to the dead backend forever.
Reproduced on 2.2.1 (cd023104) and on main (dc25d2ff).
Measurement
Cluster with 3 healthy and 3 blackholed backends, round robin, connect_timeout = 1: out of 24 requests, 12 answer 200 and 12 answer 504, and the ratio never improves. An HTTP/2 frontend behaves identically.
Root cause
- In
Mux::timeout's backend branch (lib/src/protocol/mux/mod.rs, around lines 3685-3735 onmain), a stream whose response has not started gets a504andend_stream. While the backend is still dialling, its timer is theconnect_timeoutarmed inMux::dial_backend(mod.rsaround 2520-2545). ConnectionH1::end_streamon aConnectingclient callsforce_disconnect()(lib/src/protocol/mux/h1.rsaround 1700-1717), which marks the connectionDisconnecting.- The only connect-failure accounting lives in the dead-backend branch of
Mux::ready(mod.rsaround 2913-2940:failures += 1,retry_policy.fail(), thebackend.downevent). It matchesBackendStatus::Connectingonly, so it never sees the timed-out connection.Backend::can_open()stays true and the backend keeps being selected.
Related weaknesses on the same path
- The retry budget is the hard-coded
CONN_RETRIES = 3(lib/src/server.rs:56). Operators cannot change it, either globally or per cluster. - Round robin advances with
(cursor + 1) % len(lib/src/load_balancing.rs), so a retry goes to the adjacent backend. Nothing stops it from picking a backend that already failed for this request: a request can try 3 adjacent refused backends and get503while healthy backends exist. - A connecting backend socket is marked connected on its first writable event without checking
take_error()/SO_ERROR(mod.rsaround 2751-2810). BackendMap.max_failures(lib/src/backends.rs:468) is declared and never read.
Expected behaviour
- A connect timeout counts as a backend connect failure, exactly like a refused connect (failure counter, retry policy,
backend.downevent and metrics). - A request that sent no byte to the backend is retried on another backend within the retry budget. When the budget runs out on connect failures, the answer is
503, matching the refused-connect path. A response timeout after the request was sent keeps answering504. - Retries skip backends that already failed for the same request, whatever the load-balancing algorithm.
- The retry budget can be configured: a global default (proposed: 5) with an optional per-cluster override, both changeable at runtime through the command channel and the CLI.
Mitigation today
Configure a per-cluster health_check so dead backends are taken out of rotation.
Metadata
Metadata
Assignees
Labels
No labels
Activity
FlorentinDUBOIS commentedon Oct 2, 2026
Complementary active-probe side: #1801 adds a
tcphealth-check mode (healthy iff the TCP handshake completes withintimeout, nothing sent) so a blackholed backend can be taken out of rotation before requests pay its connect timeout, without HTTP checks marking down applications that answer 3xx/401/404 on their probe path. It also makes the accepted HTTP statuses configurable (codes, ranges,any).fix(mux): bound backend failover by the frontend timeout
feat(health-check): add a TCP connect probe mode and configurable acc…
fix(mux): fail over to another backend on connect timeout (#1806)