[PR #5776] [MERGED] Server: a refused thread no longer crashes it; connection threads are capped #6489

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

📋 Pull Request Information

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

Base: main ← Head: fix/server-thread-limit-crash


📝 Commits (1)

  • 76ae6b7 Server: a refused thread no longer crashes it; connection threads are capped

📊 Changes

2 files changed (+92 additions, -6 deletions)

View changed files

📝 crates/horizon-client-render/src/streaming.rs (+13 -4)
📝 crates/horizon-client/src/lan/mod.rs (+79 -2)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #5775. On 2026-11-01 at 05:15 UTC the official server panicked when the system refused a new thread (streaming.rs:783 spawn worker: WouldBlock) and went down without saving.

  • Streaming::new: a worker that can't start is logged and skipped, and the pool runs with the workers that did start. Its idle-release count uses the real number.
  • The accept loop starts one thread per socket, where vanilla's Netty uses a few threads for every connection. Past max_players + 64 live connection threads, a new socket is now closed at once. A flood of silent sockets can no longer use up a container's thread limit. A guard frees the slot when the thread ends, panics or can't start.

Test: lan::tests::a_flood_of_silent_sockets_is_turned_away holds 65 silent sockets with a player limit of 1, checks that the 66th is closed at once, and that the slots come back once the 65 close. Without the cap it fails: the 66th is accepted and held.

Locally, thread counts on a dedicated server stayed flat through 6 waves of 8 bots joining and leaving, and 5 Nether open/close cycles (33 threads idle, 52 with the Nether open). So no leak was found. The cap is defence against bursts, and the spawn fix keeps one refused thread from killing the server.

Separately, as in vanilla's MinecraftServer.runServer (which calls stopServer() after a crash, saving players and levels), a Horizon panic should still save. That is not in this PR: the guest and level swaps (as_guest, lan.take()) make a save after a panic need its own design.

pr_ready

The one failure was mod_content::tests::builds_past_sixteen_bit_states: No space left on device (os error 28) on this machine during the run. Run alone afterwards, it passes. rustfmt is fixed in the pushed head (cargo fmt --check clean).

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 26747867d, 7 min 38 s)

Check Result
Scope ✅ 2 files, +83 −6
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (1 min 44 s)
rustfmt ❌ failed (5 s)
clippy ✅ (1 min 39 s)
tests: horizon-client, horizon-client-render ❌ 1117 passed, 1 failed (3 min 52 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 118 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer, breaking_model and 106 more
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/5776 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/server-thread-limit-crash` --- ### 📝 Commits (1) - [`76ae6b7`](https://github.com/horizon-rust/horizon/commit/76ae6b77631704f41e7e8aaed706841a865e498b) Server: a refused thread no longer crashes it; connection threads are capped ### 📊 Changes **2 files changed** (+92 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/streaming.rs` (+13 -4) 📝 `crates/horizon-client/src/lan/mod.rs` (+79 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #5775. On 2026-11-01 at 05:15 UTC the official server panicked when the system refused a new thread (`streaming.rs:783 spawn worker: WouldBlock`) and went down without saving. - `Streaming::new`: a worker that can't start is logged and skipped, and the pool runs with the workers that did start. Its idle-release count uses the real number. - The accept loop starts one thread per socket, where vanilla's Netty uses a few threads for every connection. Past `max_players + 64` live connection threads, a new socket is now closed at once. A flood of silent sockets can no longer use up a container's thread limit. A guard frees the slot when the thread ends, panics or can't start. Test: `lan::tests::a_flood_of_silent_sockets_is_turned_away` holds 65 silent sockets with a player limit of 1, checks that the 66th is closed at once, and that the slots come back once the 65 close. Without the cap it fails: the 66th is accepted and held. Locally, thread counts on a dedicated server stayed flat through 6 waves of 8 bots joining and leaving, and 5 Nether open/close cycles (33 threads idle, 52 with the Nether open). So no leak was found. The cap is defence against bursts, and the spawn fix keeps one refused thread from killing the server. Separately, as in vanilla's `MinecraftServer.runServer` (which calls `stopServer()` after a crash, saving players and levels), a Horizon panic should still save. That is not in this PR: the guest and level swaps (`as_guest`, `lan.take()`) make a save after a panic need its own design. <details><summary>pr_ready</summary> The one failure was `mod_content::tests::builds_past_sixteen_bit_states`: `No space left on device (os error 28)` on this machine during the run. Run alone afterwards, it passes. rustfmt is fixed in the pushed head (`cargo fmt --check` clean). **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 26747867d, 7 min 38 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +83 −6 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (1 min 44 s) | | rustfmt | ❌ failed (5 s) | | clippy | ✅ (1 min 39 s) | | tests: horizon-client, horizon-client-render | ❌ 1117 passed, 1 failed (3 min 52 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 118 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer, breaking_model and 106 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | </details> 🤖 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:21:24 +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#6489
No description provided.