[PR #4185] [MERGED] Server: disconnect a player whose packets pile up past a second of its budget #5469

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

📋 Pull Request Information

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

Base: main ← Head: fix/guest-inbox-cap


📝 Commits (3)

  • fa50f13 Server: disconnect a player whose packets pile up past a second of its budget
  • 4abef77 Server: cap a player's waiting packets in bytes too (16 MB)
  • 5a017c9 lan_bot: queue test packets with their size

📊 Changes

5 files changed (+101 additions, -51 deletions)

View changed files

📝 crates/horizon-client/src/lan/conn.rs (+4 -1)
📝 crates/horizon-client/src/lan/guest.rs (+4 -1)
📝 crates/horizon-client/src/lan/hub.rs (+35 -6)
📝 crates/horizon-client/src/lan/mod.rs (+2 -1)
📝 crates/horizon-client/tests/lan_bot.rs (+56 -42)

📄 Description

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

Fixes the memory exhaustion in #4179: one client could grow a Horizon server by about 1 GB a minute just by sending packets.

Cause. process_inbox handles 400 packets per player per tick, but Guest::inbox had no limit. A client sending 10 000 rotations a tick added about 9 600 packets a tick that the server kept forever, and every other player's tick paid for the longer queue.

Fix. Once a player has more than a second of that budget waiting (8 000 packets), the server:

  • drops the backlog;
  • logs <name> sent more packets than the server handles (8000 waiting);
  • disconnects them with disconnect.exceeded_packet_rate, the same reason vanilla's rate-limit gives.

A kicked player's later packets are dropped. A real client sends a few packets a tick, far below the limit, even through a long server stall. rate-limit stays off by default, as in vanilla.

A/B (playhorizon, Linux, CPUs 0-3 exclusive)

Setup: 20 mixed horizon-bots plus one --behaviour flood-packets --flood 10000 bot (#4181). 30 s warm-up, 60 s window, dedicated build --profile fast --no-default-features. Main is 061751a02.

Server RSS at end tick_lan ms/tick MSPT avg TPS Flooding bot
main, round 1 1937 MB 11.1 42.0 20.0 stays for the whole window
main, round 2 1960 MB 10.4 43.5 20.0 stays for the whole window
this PR, round 1 1039 MB 6.5 42.1 20.0 kicked 2 s after joining
this PR, round 2 963 MB 5.6 37.8 20.0 kicked 2 s after joining

For reference, runs with no abuser end at 932–1041 MB with tick_lan at 5.7–6.4 ms (#4179). Total MSPT is driven by the mob count here (530–690 at the end), so it doesn't separate the two builds.

Second commit: a cap in bytes too (16 MB)

The packet count alone let a client park 8 000 large packets. With 390 full books a tick (100 pages of 1024 characters each, about 100 kB a packet), the server reached 1.7 GB before the count tripped. The inbox now also counts each packet's bytes on the wire (NetEvent::Packet carries them). Past 16 MB waiting, the player is disconnected the same way. A real client's largest packet, a 100-page book, is a few hundred kB.

Same setup as above, with --behaviour flood-book --flood 390. The first head of this PR (packet cap only, fa50f136f) against this head (4abef77bb):

Server RSS max RSS at end tick_lan ms/tick Kicked at
packet cap only, round 1 1753 MB 1517 MB 7.9 8 000 packets
packet cap only, round 2 1735 MB 1648 MB 9.4 8 000 packets
+ byte cap, round 1 985 MB 985 MB 5.6 168 packets, 16 MB
+ byte cap, round 2 1081 MB 1081 MB 5.9 168 packets, 16 MB
pr_ready

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 061751a02, 4 min 19 s)

Check Result
Scope ✅ 5 files, +101 −51
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (1 min 5 s)
rustfmt ✅ (5 s)
clippy ✅ (20 s)
tests: horizon-client ✅ 958 passed (2 min 20 s)
doc tests ✅ 0 passed (5 s)
Parity ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, lan and 21 more

🤖 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/4185 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/guest-inbox-cap` --- ### 📝 Commits (3) - [`fa50f13`](https://github.com/horizon-rust/horizon/commit/fa50f136fee95498107165ea181b97066dcb59e8) Server: disconnect a player whose packets pile up past a second of its budget - [`4abef77`](https://github.com/horizon-rust/horizon/commit/4abef77bbae6b59b96069ed8b6863abd586957d2) Server: cap a player's waiting packets in bytes too (16 MB) - [`5a017c9`](https://github.com/horizon-rust/horizon/commit/5a017c9006017353286bcafa523df64dd8f4e5b6) lan_bot: queue test packets with their size ### 📊 Changes **5 files changed** (+101 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/conn.rs` (+4 -1) 📝 `crates/horizon-client/src/lan/guest.rs` (+4 -1) 📝 `crates/horizon-client/src/lan/hub.rs` (+35 -6) 📝 `crates/horizon-client/src/lan/mod.rs` (+2 -1) 📝 `crates/horizon-client/tests/lan_bot.rs` (+56 -42) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes the memory exhaustion in #4179: one client could grow a Horizon server by about 1 GB a minute just by sending packets. **Cause.** `process_inbox` handles 400 packets per player per tick, but `Guest::inbox` had no limit. A client sending 10 000 rotations a tick added about 9 600 packets a tick that the server kept forever, and every other player's tick paid for the longer queue. **Fix.** Once a player has more than a second of that budget waiting (8 000 packets), the server: - drops the backlog; - logs `<name> sent more packets than the server handles (8000 waiting)`; - disconnects them with `disconnect.exceeded_packet_rate`, the same reason vanilla's `rate-limit` gives. A kicked player's later packets are dropped. A real client sends a few packets a tick, far below the limit, even through a long server stall. `rate-limit` stays off by default, as in vanilla. ## A/B (playhorizon, Linux, CPUs 0-3 exclusive) Setup: 20 `mixed` horizon-bots plus one `--behaviour flood-packets --flood 10000` bot (#4181). 30 s warm-up, 60 s window, dedicated build `--profile fast --no-default-features`. Main is 061751a02. | | Server RSS at end | `tick_lan` ms/tick | MSPT avg | TPS | Flooding bot | |---|---|---|---|---|---| | main, round 1 | 1937 MB | 11.1 | 42.0 | 20.0 | stays for the whole window | | main, round 2 | 1960 MB | 10.4 | 43.5 | 20.0 | stays for the whole window | | this PR, round 1 | **1039 MB** | **6.5** | 42.1 | 20.0 | kicked 2 s after joining | | this PR, round 2 | **963 MB** | **5.6** | 37.8 | 20.0 | kicked 2 s after joining | For reference, runs with no abuser end at 932–1041 MB with `tick_lan` at 5.7–6.4 ms (#4179). Total MSPT is driven by the mob count here (530–690 at the end), so it doesn't separate the two builds. ## Second commit: a cap in bytes too (16 MB) The packet count alone let a client park 8 000 large packets. With 390 full books a tick (100 pages of 1024 characters each, about 100 kB a packet), the server reached 1.7 GB before the count tripped. The inbox now also counts each packet's bytes on the wire (`NetEvent::Packet` carries them). Past 16 MB waiting, the player is disconnected the same way. A real client's largest packet, a 100-page book, is a few hundred kB. Same setup as above, with `--behaviour flood-book --flood 390`. The first head of this PR (packet cap only, fa50f136f) against this head (4abef77bb): | | Server RSS max | RSS at end | `tick_lan` ms/tick | Kicked at | |---|---|---|---|---| | packet cap only, round 1 | 1753 MB | 1517 MB | 7.9 | 8 000 packets | | packet cap only, round 2 | 1735 MB | 1648 MB | 9.4 | 8 000 packets | | + byte cap, round 1 | **985 MB** | 985 MB | 5.6 | 168 packets, 16 MB | | + byte cap, round 2 | **1081 MB** | 1081 MB | 5.9 | 168 packets, 16 MB | <details><summary>pr_ready</summary> **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 061751a02, 4 min 19 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +101 −51 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (1 min 5 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (20 s) | | tests: horizon-client | ✅ 958 passed (2 min 20 s) | | doc tests | ✅ 0 passed (5 s) | | Parity | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, lan and 21 more | </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 05:12:48 +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#5469
No description provided.