Skip to content

fix(mux): a backend connect timeout answers 504 instead of failing over to a healthy backend #1800

Closed

Description

@FlorentinDUBOIS

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 on main), a stream whose response has not started gets a 504 and end_stream. While the backend is still dialling, its timer is the connect_timeout armed in Mux::dial_backend (mod.rs around 2520-2545).
  • ConnectionH1::end_stream on a Connecting client calls force_disconnect() (lib/src/protocol/mux/h1.rs around 1700-1717), which marks the connection Disconnecting.
  • The only connect-failure accounting lives in the dead-backend branch of Mux::ready (mod.rs around 2913-2940: failures += 1, retry_policy.fail(), the backend.down event). It matches BackendStatus::Connecting only, 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 get 503 while healthy backends exist.
  • A connecting backend socket is marked connected on its first writable event without checking take_error() / SO_ERROR (mod.rs around 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.down event 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 answering 504.
  • 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.

Activity

  1. FlorentinDUBOIS commented on Oct 2, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Complementary active-probe side: #1801 adds a tcp health-check mode (healthy iff the TCP handshake completes within timeout, 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).

  2. added a commit that references this issue on Oct 2, 2026
    e959838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions