[PR #4208] [MERGED] Time out a server that stops answering, with vanilla's disconnect reasons #5485

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4208
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3520-read-timeout


📝 Commits (1)

  • 4f03c8a Time out a server that stops answering, with vanilla's disconnect reasons

📊 Changes

6 files changed (+162 additions, -20 deletions)

View changed files

📝 crates/horizon-client/src/lan/conn.rs (+1 -1)
📝 crates/horizon-client/src/net.rs (+109 -13)
📝 crates/horizon-protocol/examples/probe.rs (+1 -1)
📝 crates/horizon-protocol/src/connection.rs (+32 -4)
📝 crates/horizon-protocol/src/lib.rs (+18 -0)
📝 tools/port_map/rest-010.tsv (+1 -1)

📄 Description

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

What and why

Part of #3520 (ledger row Connection#exceptionCaught).

A server that stops answering never timed out. net.rs connected with Connection::connect_server(host, port, 10 s), but that is only a connect timeout. The login, configuration and play loops then blocked in reader.recv() with no read timeout (only the server-list ping() set one). When a server froze, or the network went away without a TCP reset, the player stayed in a frozen world indefinitely. I reproduced this against vanilla server.jar by suspending the Java process: the main build was still playing more than 2 minutes later.

Vanilla's client channel initializer (Connection$1.initChannel) adds ReadTimeoutHandler(30). The fix gives the client socket the same 30 s read timeout (READ_TIMEOUT, set in the new connect_tcp, which also covers the friends relay tunnel). A server sends a keep-alive every 15 s in both configuration and play, so a healthy connection never comes close to the limit. The integrated server's in-memory pipe is left unchanged: vanilla's local channel (Connection$3) has no timeout, so pausing single player still never disconnects.

Disconnect reasons were raw Rust or OS errors. Any failed read was shown as e.to_string(). On Windows that is the localized OS message (for example ... (os error 10060) in the system language). The new connection_lost follows Connection.exceptionCaught and Connection.channelInactive:

  • a read timeout gives disconnect.timeout ("Timed out")
  • the server closing the stream gives disconnect.endOfStream ("End of stream")
  • any other failure (I/O error, malformed configuration or login packet) gives disconnect.genericReason with "Internal Exception: " + error, as vanilla builds it

To support this, horizon_protocol::Error gains timed_out() / is_timed_out() and end_of_stream() / is_end_of_stream(). ConnReader::recv now reports a socket read timeout (TimedOut on Windows, WouldBlock on Unix) as timed_out(). Previously it reported whatever the OS said. Two places that matched the old strings now call the predicates: the LAN host's read_loop and the protocol probe example. The probe's contains("timed out") check never matched on a non-English Windows. The LAN host's own 30 s read timeout on a guest now also ends with "Timed out" instead of the OS text, as vanilla's server reports it.

Auto-reconnect is unaffected. These are still connection failures (from_server: false), which it retries as before.

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

  • net.minecraft.network.Connection$1.initChannel: pipeline.addLast("timeout", new ReadTimeoutHandler(30)) (javap: new ReadTimeoutHandler, bipush 30). Connection$3 (the connectToLocalServer in-memory initializer) adds none.
  • net.minecraft.network.Connection.exceptionCaught: a TimeoutException disconnects with disconnect.timeout. Anything else disconnects with disconnect.genericReason and the argument "Internal Exception: " + throwable (the makeConcatWithConstants recipe Internal Exception: \u0001). In 26.3 the en_us text of disconnect.genericReason is just %s.
  • net.minecraft.network.Connection.channelInactive: disconnect.endOfStream.
  • Ledger: tools/port_map/rest-010.tsv row Connection#exceptionCaught changes from inline … gap: player to port crates/horizon-client/src/net.rs::connection_lost.
  • No parity harness covers network failures. The tests below check the behaviour instead.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran these steps by hand (Windows 11, CARGO_TARGET_DIR set to a private folder):

cargo fmt --all -- --check                                        # ok
cargo clippy -p horizon-protocol --all-targets -- -D warnings     # ok
cargo clippy -p horizon-client --all-targets -- -D warnings       # ok
cargo test -p horizon-protocol --lib                              # 111 passed
cargo test -p horizon-client --lib net::tests::                   # 8 passed
cargo test -p horizon-client --lib lan::conn::                    # 7 passed
cargo test -p horizon-client --lib reconnect::                    # 6 passed
python tools/check_public_tree.py                                 # passed

New tests:

  • horizon-protocol connection::tests::a_silent_peer_times_out_and_a_closed_one_ends_the_stream
  • horizon-client net::tests::a_server_that_stops_answering_times_out: a TCP server accepts and then sends nothing; receive_play must end with "Timed out". Uses a 300 ms timeout injected through connect_tcp.
  • horizon-client net::tests::lost_connections_read_like_vanillas_disconnect_reasons

To show the tests fail before the fix, I reverted only the behaviour and kept the helper signatures so they still compile: no set_read_timeout in connect_tcp, connection_lost returning e.to_string(), and the old recv read handling. All three new tests then failed:

  • a_silent_peer_…: panicked with the raw OS text Попытка установить соединение была безуспешной, … (os error 10060).
  • a_server_that_stops_answering_times_out: the connection never timed out (still blocked after 10 s).
  • lost_connections_…: left: "Connection closed by the server", right: "End of stream".

With the fix, all three pass.

python tools/port_ledger.py build fails on this Windows checkout (it needs decompiled sources), so CI should run the ledger check.

In game (fast build, vanilla 26.3 server.jar on localhost, offline mode):

  • Before (main): joined, suspended the server's Java process, and the game stayed on playing in the frozen world for more than 2 minutes.
  • After: joined, suspended the server at 12:58:47. At 12:59:17, exactly 30 s later, the game showed "Connection Lost / Timed out" with "Back to Server List". The log says Horizon: disconnected: Timed out.
  • LAN guest (after): stayed connected to a Horizon LAN host (server thread) for over 100 s while the host sat in its pause menu. Keep-alives keep it alive.
  • Single player on the server thread (after): paused for 65 s, resumed, and was still playing. The in-memory pipe has no timeout.

Screenshots

after: 30 s after the server stops answering, the client shows Connection Lost / Timed out (before: the world stays frozen with no way out)

Before: the world stays on screen indefinitely after the server freezes, and nothing tells the player the connection is gone.

After: 30 s after the server stops answering, the game shows the vanilla "Connection Lost" screen with "Timed out" and a "Back to Server List" button.

🤖 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/4208 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3520-read-timeout` --- ### 📝 Commits (1) - [`4f03c8a`](https://github.com/horizon-rust/horizon/commit/4f03c8a87378dc054a1f7e06a8e411bc275972f3) Time out a server that stops answering, with vanilla's disconnect reasons ### 📊 Changes **6 files changed** (+162 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/conn.rs` (+1 -1) 📝 `crates/horizon-client/src/net.rs` (+109 -13) 📝 `crates/horizon-protocol/examples/probe.rs` (+1 -1) 📝 `crates/horizon-protocol/src/connection.rs` (+32 -4) 📝 `crates/horizon-protocol/src/lib.rs` (+18 -0) 📝 `tools/port_map/rest-010.tsv` (+1 -1) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why Part of #3520 (ledger row `Connection#exceptionCaught`). **A server that stops answering never timed out.** `net.rs` connected with `Connection::connect_server(host, port, 10 s)`, but that is only a connect timeout. The login, configuration and play loops then blocked in `reader.recv()` with no read timeout (only the server-list `ping()` set one). When a server froze, or the network went away without a TCP reset, the player stayed in a frozen world indefinitely. I reproduced this against vanilla `server.jar` by suspending the Java process: the main build was still `playing` more than 2 minutes later. Vanilla's client channel initializer (`Connection$1.initChannel`) adds `ReadTimeoutHandler(30)`. The fix gives the client socket the same 30 s read timeout (`READ_TIMEOUT`, set in the new `connect_tcp`, which also covers the friends relay tunnel). A server sends a keep-alive every 15 s in both configuration and play, so a healthy connection never comes close to the limit. The integrated server's in-memory pipe is left unchanged: vanilla's local channel (`Connection$3`) has no timeout, so pausing single player still never disconnects. **Disconnect reasons were raw Rust or OS errors.** Any failed read was shown as `e.to_string()`. On Windows that is the localized OS message (for example `... (os error 10060)` in the system language). The new `connection_lost` follows `Connection.exceptionCaught` and `Connection.channelInactive`: - a read timeout gives `disconnect.timeout` ("Timed out") - the server closing the stream gives `disconnect.endOfStream` ("End of stream") - any other failure (I/O error, malformed configuration or login packet) gives `disconnect.genericReason` with `"Internal Exception: " + error`, as vanilla builds it To support this, `horizon_protocol::Error` gains `timed_out()` / `is_timed_out()` and `end_of_stream()` / `is_end_of_stream()`. `ConnReader::recv` now reports a socket read timeout (`TimedOut` on Windows, `WouldBlock` on Unix) as `timed_out()`. Previously it reported whatever the OS said. Two places that matched the old strings now call the predicates: the LAN host's `read_loop` and the protocol `probe` example. The probe's `contains("timed out")` check never matched on a non-English Windows. The LAN host's own 30 s read timeout on a guest now also ends with "Timed out" instead of the OS text, as vanilla's server reports it. Auto-reconnect is unaffected. These are still connection failures (`from_server: false`), which it retries as before. ## Kind - [x] 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 - `net.minecraft.network.Connection$1.initChannel`: `pipeline.addLast("timeout", new ReadTimeoutHandler(30))` (javap: `new ReadTimeoutHandler`, `bipush 30`). `Connection$3` (the `connectToLocalServer` in-memory initializer) adds none. - `net.minecraft.network.Connection.exceptionCaught`: a `TimeoutException` disconnects with `disconnect.timeout`. Anything else disconnects with `disconnect.genericReason` and the argument `"Internal Exception: " + throwable` (the `makeConcatWithConstants` recipe `Internal Exception: \u0001`). In 26.3 the en_us text of `disconnect.genericReason` is just `%s`. - `net.minecraft.network.Connection.channelInactive`: `disconnect.endOfStream`. - Ledger: `tools/port_map/rest-010.tsv` row `Connection#exceptionCaught` changes from `inline … gap: player` to `port crates/horizon-client/src/net.rs::connection_lost`. - No parity harness covers network failures. The tests below check the behaviour instead. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran these steps by hand (Windows 11, `CARGO_TARGET_DIR` set to a private folder): ``` cargo fmt --all -- --check # ok cargo clippy -p horizon-protocol --all-targets -- -D warnings # ok cargo clippy -p horizon-client --all-targets -- -D warnings # ok cargo test -p horizon-protocol --lib # 111 passed cargo test -p horizon-client --lib net::tests:: # 8 passed cargo test -p horizon-client --lib lan::conn:: # 7 passed cargo test -p horizon-client --lib reconnect:: # 6 passed python tools/check_public_tree.py # passed ``` New tests: - `horizon-protocol` `connection::tests::a_silent_peer_times_out_and_a_closed_one_ends_the_stream` - `horizon-client` `net::tests::a_server_that_stops_answering_times_out`: a TCP server accepts and then sends nothing; `receive_play` must end with "Timed out". Uses a 300 ms timeout injected through `connect_tcp`. - `horizon-client` `net::tests::lost_connections_read_like_vanillas_disconnect_reasons` To show the tests fail before the fix, I reverted only the behaviour and kept the helper signatures so they still compile: no `set_read_timeout` in `connect_tcp`, `connection_lost` returning `e.to_string()`, and the old `recv` read handling. All three new tests then failed: - `a_silent_peer_…`: panicked with the raw OS text `Попытка установить соединение была безуспешной, … (os error 10060)`. - `a_server_that_stops_answering_times_out`: `the connection never timed out` (still blocked after 10 s). - `lost_connections_…`: `left: "Connection closed by the server"`, `right: "End of stream"`. With the fix, all three pass. `python tools/port_ledger.py build` fails on this Windows checkout (it needs decompiled sources), so CI should run the ledger check. In game (fast build, vanilla 26.3 `server.jar` on localhost, offline mode): - **Before (main):** joined, suspended the server's Java process, and the game stayed on `playing` in the frozen world for more than 2 minutes. - **After:** joined, suspended the server at 12:58:47. At 12:59:17, exactly 30 s later, the game showed "Connection Lost / Timed out" with "Back to Server List". The log says `Horizon: disconnected: Timed out`. - **LAN guest (after):** stayed connected to a Horizon LAN host (server thread) for over 100 s while the host sat in its pause menu. Keep-alives keep it alive. - **Single player on the server thread (after):** paused for 65 s, resumed, and was still playing. The in-memory pipe has no timeout. ## Screenshots ![after: 30 s after the server stops answering, the client shows Connection Lost / Timed out (before: the world stays frozen with no way out)](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3520-read-timeout-1.png) Before: the world stays on screen indefinitely after the server freezes, and nothing tells the player the connection is gone. After: 30 s after the server stops answering, the game shows the vanilla "Connection Lost" screen with "Timed out" and a "Back to Server List" button. 🤖 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 05:12:55 +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#5485
No description provided.