[PR #1630] [MERGED] Connect to a server's IPv4 address first, as vanilla does #3645

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1630
Author: @some-du6e
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/25/2026
Merged by: @ludovic111

Base: main ← Head: fix/ipv4-first


📝 Commits (3)

  • be34f4c Connect to a server's IPv4 address first, as vanilla does
  • 3e3ab7a Merge main into fix/ipv4-first: IPv4 first for SRV targets too
  • 96b6ed4 Test that a connection reaches IPv4 first and report the first address's error

📊 Changes

1 file changed (+82 additions, -10 deletions)

View changed files

📝 crates/horizon-protocol/src/connection.rs (+82 -10)

📄 Description

🤖 Opened by some-du6e's AI agent (Claude Code, Claude Opus 5.5), not by some-du6e themselves.

What and why

On macOS, joining a public server by its hostname failed with "Connection reset by peer (os error 54)", but joining its IPv4 address worked. The server's IPv6 address accepts TCP and then resets the connection. macOS's resolver lists IPv6 first, and Horizon tried the addresses in resolver order, so it never got as far as the IPv4 one that works. Vanilla gets in over IPv4 because Java prefers IPv4 by default.

Every connection to a server now tries the host's IPv4 addresses before its IPv6 ones: joining, the server-list ping, and SRV redirect targets (Ludovic's merge moved the sort into connect_addresses, which connect and connect_server share). Within each family it keeps the resolver's order. If an IPv4 address refuses the connection, it still falls back to IPv6. A server that accepts and then resets is only avoided by the order, as in vanilla. When every address fails, the error shown is the first address's, the one vanilla would report, not an IPv6 fallback's "no route to host".

Vanilla reference

ServerNameResolver resolves both the original host and an SRV target through ServerAddressResolver.SYSTEM, which calls InetAddress.getByName. That follows Java's default java.net.preferIPv6Addresses=false: IPv4 first. No harness covers this (it's networking). Unit tests check the ordering, that a connection lands on 127.0.0.1 when [::1] is listening too and listed first (it fails without the sort), and the fallback to IPv6.

To check it end to end on Linux, where localhost resolves to ::1 first just as macOS lists IPv6 first, a fake server listened on both: [::1] accepted and then reset, and 127.0.0.1 answered the login. protocol_probe localhost:<port> built from main failed with "Connection reset by peer (os error 104)". Built from this branch, it reached the IPv4 listener.

Self-check

pr_ready (tools/pr_ready.py --quick --base origin/main on swiss, against origin/main at 76638aaf8, 4 min 42 s)

Check Result
Scope ✅ 1 files, +82 −10
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (8 s)
clippy ✅ (4 min 19 s)
tests: horizon-protocol ✅ 87 passed (11 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): 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)

Tested on macOS (Apple Silicon) against that server (Paper, online mode): joining by hostname now works.

Note

Filed by Claude Opus 5.5 using Claude Code, for some-du6e.

🤖 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/1630 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/ipv4-first` --- ### 📝 Commits (3) - [`be34f4c`](https://github.com/horizon-rust/horizon/commit/be34f4cd5f1db4dc36eb44d92d0fccfdfd9afd54) Connect to a server's IPv4 address first, as vanilla does - [`3e3ab7a`](https://github.com/horizon-rust/horizon/commit/3e3ab7a4138e58133da309bccb1fe7570152d4a8) Merge main into fix/ipv4-first: IPv4 first for SRV targets too - [`96b6ed4`](https://github.com/horizon-rust/horizon/commit/96b6ed4916d6490be22fe2b0faaa7fe00ee546f3) Test that a connection reaches IPv4 first and report the first address's error ### 📊 Changes **1 file changed** (+82 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-protocol/src/connection.rs` (+82 -10) </details> ### 📄 Description > 🤖 Opened by some-du6e's AI agent (Claude Code, Claude Opus 5.5), not by some-du6e themselves. ## What and why On macOS, joining a public server by its hostname failed with "Connection reset by peer (os error 54)", but joining its IPv4 address worked. The server's IPv6 address accepts TCP and then resets the connection. macOS's resolver lists IPv6 first, and Horizon tried the addresses in resolver order, so it never got as far as the IPv4 one that works. Vanilla gets in over IPv4 because Java prefers IPv4 by default. Every connection to a server now tries the host's IPv4 addresses before its IPv6 ones: joining, the server-list ping, and SRV redirect targets (Ludovic's merge moved the sort into `connect_addresses`, which `connect` and `connect_server` share). Within each family it keeps the resolver's order. If an IPv4 address refuses the connection, it still falls back to IPv6. A server that accepts and then resets is only avoided by the order, as in vanilla. When every address fails, the error shown is the first address's, the one vanilla would report, not an IPv6 fallback's "no route to host". ## Vanilla reference `ServerNameResolver` resolves both the original host and an SRV target through `ServerAddressResolver.SYSTEM`, which calls `InetAddress.getByName`. That follows Java's default `java.net.preferIPv6Addresses=false`: IPv4 first. No harness covers this (it's networking). Unit tests check the ordering, that a connection lands on 127.0.0.1 when `[::1]` is listening too and listed first (it fails without the sort), and the fallback to IPv6. To check it end to end on Linux, where `localhost` resolves to `::1` first just as macOS lists IPv6 first, a fake server listened on both: `[::1]` accepted and then reset, and 127.0.0.1 answered the login. `protocol_probe localhost:<port>` built from main failed with "Connection reset by peer (os error 104)". Built from this branch, it reached the IPv4 listener. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base origin/main` on swiss, against origin/main at 76638aaf8, 4 min 42 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +82 −10 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (8 s) | | clippy | ✅ (4 min 19 s) | | tests: horizon-protocol | ✅ 87 passed (11 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): 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) | Tested on macOS (Apple Silicon) against that server (Paper, online mode): joining by hostname now works. > [!NOTE] > Filed by Claude Opus 5.5 using Claude Code, for some-du6e. 🤖 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 04:11:07 +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#3645
No description provided.