[PR #6363] [MERGED] Play with friends: the host attaches from any port when its direct port times out #6827

Closed
opened 2026-11-03 06:27:38 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6363
Author: @Ragbie
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/relay-attach-time-wait


📝 Commits (1)

  • f3de190 Play with friends: the host attaches from any port when its direct port times out

📊 Changes

1 file changed (+27 additions, -4 deletions)

View changed files

📝 crates/horizon-friends/src/host.rs (+27 -4)

📄 Description

🤖 Opened by Ragbie's AI agent (Claude Code, Opus 5.5), not by Ragbie personally.

What and why

A host behind a relay that runs on Windows couldn't take a second relayed guest for a couple of minutes after the first left: the guest waited ~10 s and got "Your friend's game didn't answer." (HostUnreachable). horizon-relay's a_short_code_through_a_self_hosted_relay fails on every Windows run because of it (tunnel.rs:200:63); CI's Linux run passes.

The host attaches every relayed session from its direct port, so each attach to a relay reuses one address pair. The relay closes a finished session first and keeps the pair in TIME_WAIT (127.0.0.1:57988 127.0.0.1:57990 TIME_WAIT, traced with netstat). Windows ignores a new SYN for that pair (Linux takes it), so the host's next attach times out after 5 s instead of failing with AddrInUse, connect_from's fallback to another port never runs, and the relay's 10 s attach_wait expires.

  • connect_relay: the addresses that timed out from the direct port get one more try from any port, after every address had its try from the direct port, so a dead IPv6 route still costs one 5 s timeout before IPv4, as before.
  • serve_relayed: an attach that didn't come from the direct port (this fallback, or connect_from's AddrInUse one) no longer offers what the relay saw of it as a direct candidate; nothing listens on that port.
  • The direct race's dials (direct::dial) are unchanged: timing out is normal while punching, they keep their port.

Fixes #6342

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (Play with Friends). Checked by horizon-relay's tests/tunnel.rs.

Other projects' code

none

Self-check

cargo test -p horizon-relay --test tunnel: before, a_short_code_through_a_self_hosted_relay failed every Windows run (HostUnreachable); after, 9 passed three times on Windows 11 and twice in a Linux rust:1.98 container; horizon-friends --lib 35 passed on both. pr_ready doesn't run the relay's tests for a horizon-friends change, hence these.

pr_ready (tools/pr_ready.py --base upstream/main on Evrim-PC, against upstream/main at 62bdd29b2, 7 min 41 s)

Check Result
Scope ✅ 1 files, +27 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 594 passed (1 min 56 s)
rustfmt ✅ (9 s)
clippy ✅ (45 s)
tests: horizon-friends ✅ 35 passed (3 s)
doc tests ✅ 0 passed
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (1 min 47 s)
launcher tests ✅ 386 passed (2 min 54 s)
Parity ➖ not run (no vanilla data here): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6363 **Author:** [@Ragbie](https://github.com/Ragbie) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/relay-attach-time-wait` --- ### 📝 Commits (1) - [`f3de190`](https://github.com/horizon-rust/horizon/commit/f3de190aaf258d2464a62322e766a077a01fda12) Play with friends: the host attaches from any port when its direct port times out ### 📊 Changes **1 file changed** (+27 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-friends/src/host.rs` (+27 -4) </details> ### 📄 Description > 🤖 Opened by Ragbie's AI agent (Claude Code, Opus 5.5), not by Ragbie personally. ## What and why A host behind a relay that runs on Windows couldn't take a second relayed guest for a couple of minutes after the first left: the guest waited ~10 s and got "Your friend's game didn't answer." (`HostUnreachable`). `horizon-relay`'s `a_short_code_through_a_self_hosted_relay` fails on every Windows run because of it (`tunnel.rs:200:63`); CI's Linux run passes. The host attaches every relayed session from its direct port, so each attach to a relay reuses one address pair. The relay closes a finished session first and keeps the pair in TIME_WAIT (`127.0.0.1:57988 127.0.0.1:57990 TIME_WAIT`, traced with `netstat`). Windows ignores a new SYN for that pair (Linux takes it), so the host's next attach times out after 5 s instead of failing with `AddrInUse`, `connect_from`'s fallback to another port never runs, and the relay's 10 s `attach_wait` expires. - `connect_relay`: the addresses that timed out from the direct port get one more try from any port, after every address had its try from the direct port, so a dead IPv6 route still costs one 5 s timeout before IPv4, as before. - `serve_relayed`: an attach that didn't come from the direct port (this fallback, or `connect_from`'s `AddrInUse` one) no longer offers what the relay saw of it as a direct candidate; nothing listens on that port. - The direct race's dials (`direct::dial`) are unchanged: timing out is normal while punching, they keep their port. Fixes #6342 ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (Play with Friends). Checked by `horizon-relay`'s `tests/tunnel.rs`. ## Other projects' code none ## Self-check `cargo test -p horizon-relay --test tunnel`: before, `a_short_code_through_a_self_hosted_relay` failed every Windows run (`HostUnreachable`); after, 9 passed three times on Windows 11 and twice in a Linux `rust:1.98` container; `horizon-friends --lib` 35 passed on both. `pr_ready` doesn't run the relay's tests for a `horizon-friends` change, hence these. **pr_ready** (`tools/pr_ready.py --base upstream/main` on Evrim-PC, against upstream/main at 62bdd29b2, 7 min 41 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +27 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 594 passed (1 min 56 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (45 s) | | tests: horizon-friends | ✅ 35 passed (3 s) | | doc tests | ✅ 0 passed | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 min 47 s) | | launcher tests | ✅ 386 passed (2 min 54 s) | | Parity | ➖ not run (no vanilla data here): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:38 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6827
No description provided.