Skip to content

Keep a failover route down until a probe's connection stays open - #86

Merged
kriszyp merged 4 commits into
mainfrom
fix/failover-probe-readiness
Nov 6, 2026
Merged

kriszyp merged 4 commits into
mainfrom
fix/failover-probe-readiness

Conversation

@kriszyp

@kriszyp kriszyp commented Nov 6, 2026 •

Copy link
Copy Markdown
Member
Kyle holds a red flag and a stopwatch while a robot slams a hatch on nothing

⊙ Problem

After a local Harper restart, a failover route can report up about 1 s before Harper serves. New connections in that window drop with route error stream. Docker accepts them, not Harper. While Harper's socket metadata is missing, host-manager points the route at a published port, where docker-proxy accepts before Harper binds. symphony's probe counts that accept as recovery. After a crash, the reload onto that port brings the route up with no probe.

💡 Solution

⚖️ Alternatives

  • Fixed hold-down — docker-proxy accepts for Harper's whole boot, so no fixed time is right.
  • Wait for the local upstream's first byte on passthrough routes — loses nothing, but adds work per connection and reverses a recorded boundary.
  • Drain host-manager's fallback route until the sockets return — covers every case with a peer, and the fleet change makes it unnecessary.

🤔 Why fix this here if the fleet is turning off Docker's userland proxy?

userland-proxy: false is the primary fix: a published port then refuses until Harper binds, and the existing forward covers every case. This PR keeps routeHealth and localUp truthful until that ships, and behind any other proxy. Once it is everywhere, Fabric no longer depends on this probe.

🤔 Is requiring upstreams to hold an idle connection for 250 ms acceptable?

A failover upstream that closes an idle connection sooner never clears once marked, so its traffic stays on peers. Harper holds one for 10 s. Failover is opt-in, and Fabric is its only known user.

🤔 Should a route with no mark stay exposed?

Yes, until the fleet change: connections in the window still fail. Marking on a stream error would fix this, but the copying code cannot tell a client's reset from an upstream's, so a client could take a route down.

🔧 Changes

How a restart reaches the window

docker-proxy accepts first and dials the container second, so it accepts for as long as Harper is booting.

sequenceDiagram
    participant HM as host-manager
    participant S as symphony
    participant P as docker-proxy
    participant H as Harper
    Note over H: sockets gone
    HM->>S: reload: route is now TCP passthrough
    Note over P: binds when the container starts
    S->>P: probe connects
    P->>H: dial
    H-->>P: refused
    P-->>S: closes
    Note over S: before: up. now: stays down
    Note over H: binds after components load
    S->>P: probe connects, stays open 250 ms
    Note over S: up
    HM->>S: reload: route is UDS again
Loading
How the route got there Before Now
Stop, later start: traffic marked the TCP route Probe clears on docker-proxy's accept, connections drop until Harper binds Peers serve until Harper binds
Crash restart: reload moves a down route to a TCP destination Up at the reload with no probe, connections drop until Harper binds Peers serve until Harper binds
No mark when the window opens: a quiet route, or a planned restart whose drain is released early Connections drop Connections still drop, until userland-proxy: false

Files

✅ Verification

  • End-to-end route: 8 new integration tests with real proxies and a docker-proxy fixture, one through a real updateConfig flip. 5 fail on base; the other 3 guard behavior that must not change.
  • On this head: npm test passes 267 of 267, cargo test passes 242 with 1 ignored, and cargo clippy --all-targets and cargo fmt --check are clean.
  • CI: Linux passes. macOS did not run: GitHub refuses the macos-14 runner, also on a retry.
  • Not run: real docker-proxy or Fabric stage: the worker has no Docker. On stage, ss -ltnp 'sport = :9936' during a restart would confirm the accepter.
  • Docs: the README here; a local HarperFast/documentation checkout has no symphony page.

Performance: a client connect does less: one relaxed load and, on a marked slot, one compare-and-swap are gone. Everything added runs on the probe task or at reload. A probe pass can take up to ceil(endpoints / 64) x 1.25 s.

How the accepter was identified
Check Result
Harper 5.3.5, 4 boots, and harper-pro 5.3.4, 3 boots, polled with a PROXY header and a GET Only ECONNREFUSED, then served. No connection accepted and then closed, and one socket inode per boot
Harper bind order in 5.3.5 and main Components load first, then listenOnPorts
host-manager, missing socket metadata Publishes TCP passthrough to <loopback>:9936, a Docker publish
Fleet daemon.json Does not set userland-proxy, whose default is true
moby tcp_proxy_linux.go Accept, then DialTCP, then client.Close() on a failed dial
This repo on base with a docker-proxy fixture, stop then start 9 of 9 dropped with stream, localUp: true, refusingSlots: 0
Same, crash path through a real reload 10 of 10 dropped, routeHealth up at the reload

The socket files' modification times were later than the first drops in the stage run because no Unix socket was in the path yet.

Test cases

Fail on base, pass here:

  • A Unix socket that accepts and closes stays out of rotation until it serves. Peers serve meanwhile, with no stream errors.
  • A proxy in front of a refusing backend does not count as up.
  • A reload onto a proxy already accepting keeps a down route down, with no routeHealth up, then back to the Unix socket.
  • A probe of a replaced endpoint does not report the new route up.
  • An upstream that closes idle connections after 50 ms stays down.

Pass on base and here:

  • A reload onto a healthy endpoint recovers.
  • 65 distinct endpoints all clear, across two probe batches.
  • The probe does not see a close after 1 s, showing its limit.

Rust: a connect to a marked slot leaves it marked, probe outcomes (close, reset, silent, a banner, an answer and close, a late close, a peer that keeps writing), and which endpoints a reload marks.

Refs Don't route to a restarted upstream until it serves, not just accepts.

🤖 Generated by Claude Code (Claude Opus 5.5); posted via @kriszyp.

Related PRs: #85 overlaps, 2 others independent

Complexity: medium

Origin — the dispatch brief this PR was written from

Don't route to a restarted upstream until it serves, not just accepts

CONSULT FIRST: investigate, then open a needs-input consultation with your findings and proposed fix before implementing. Issue #84: when a local Harper restarts, symphony's failover probe (connect-and-close, src/failover.rs probe) clears the route's down mark about 1 s before Harper serves on its per-thread Unix socket, and connections in that window are accepted then closed with no response (route error 'stream', 4-7 ms). Find out what accepts during that window and decide where the fix belongs (Harper binding/accepting before it can serve, a symphony probe/hold-down change, or both), then implement the agreed symphony part and open a draft PR. If the root fix is in Harper, say so and draft a HarperFast/harper issue body in the consultation rather than changing Harper from this task.

Acceptance

  • Consultation first, with: what accepts during the window (evidence from Harper source and/or a local reproduction), and the proposed fix split between Harper and symphony.
  • For the symphony part: a test with a UDS upstream that accepts and immediately closes for a period after coming back; no new connection is routed to it during that period (or it is retried at a peer before any byte reaches the client).
  • npm test, cargo test, cargo clippy --all-targets, cargo fmt --check pass.
  • Do not change Harper or host-manager from this task.

Dispatch: task symphony-84-failback-readiness · queued by kris-session · ran by claude/opus/xhigh · worker kzyp-xps-1

Review-Coverage: authored=claude; ran=cursor-composer,codex,gemini,cursor-grok; late=cursor-grok:adjudicated; adjudicated=domain; declined=muse; rounds=4; full=2 @ 18b1596

Review-Attention: read ~4m @ 18b1596

kriszyp and others added 4 commits November 6, 2026 12:31
A connect-and-close probe brought a route back as soon as anything accepted.
On Fabric that is docker-proxy on the fallback route's published port, which
accepts before Harper binds and closes when its dial is refused, so every new
connection in that window was dropped with route error `stream`.

- The probe sends nothing and needs the connection to stay open for 250 ms.
- Only the probe clears a slot; a client connect no longer does.
- A reload of a down route starts the endpoints it did not have as refusing,
  since fresh health reads as up and an unmarked slot is never probed.
- Health transitions are read from the live table after a probe pass.

Refs #84

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-84-failback-readiness
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-84-failback-readiness
Pins that a peer writing continuously cannot hold a probe past its deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-84-failback-readiness
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-84-failback-readiness

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the health-checking and failover probing mechanism to handle upstreams that accept connections before they are actually ready to serve (such as Docker's userland proxy). Specifically, a successful client connection no longer clears a slot's refused status; instead, only the background probe can clear it, and only if the connection remains open for at least 250 milliseconds. Additionally, when a down route is reloaded, any new endpoints it did not previously have are initialized as refusing until they are verified by a probe. Extensive tests and documentation updates have been added to support these changes. I have no feedback to provide as there are no review comments to assess.

@kriszyp
kriszyp marked this pull request as ready for review November 6, 2026 20:33
@kriszyp
kriszyp merged commit 47dd31a into main Nov 6, 2026
22 of 24 checks passed
@dawsontoth
dawsontoth deleted the fix/failover-probe-readiness branch November 20, 2026 17:47
kriszyp added a commit that referenced this pull request Nov 28, 2026
Sync package + platform + crate versions to 1.8.0. Adds opt-in mtls.failureHoldMs/failureHoldJitter (#98), case-insensitive SNI/Host matching (#94), and failover forwarding/probe fixes (#85, #86).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant