[PR #5952] [MERGED] Dedicated server: a panic in the tick still saves the world #6582

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

📋 Pull Request Information

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

Base: main ← Head: fix/dedicated-crash-save


📝 Commits (3)

  • b183f74 Dedicated server: a panic in the tick still saves the world, as runServer's finally does
  • 8eff240 Dedicated server: test that a panic in a player's turn or with the hub out saves the world and no player file
  • 010239c Crash fixture: scan the guests only when HORIZON_CRASH_FIXTURE names the point

📊 Changes

3 files changed (+278 additions, -10 deletions)

View changed files

📝 crates/horizon-client/src/game/dedicated.rs (+106 -10)
📝 crates/horizon-client/src/game/lan_actions.rs (+3 -0)
➕ tools/test_dedicated_crash_save.py (+169 -0)

📄 Description

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

Closes #5788 as far as the issue asks: the world is saved after a panic. Player files are saved only when it is safe (below).

What vanilla does

MinecraftServer.runServer catches whatever the tick loop throws, writes the crash report, then calls stopServer(), which saves every player and every level.

What was wrong

A panic on the dedicated tick thread unwound out of run_dedicated without stop_dedicated: nothing since the last autosave was written (the official server lost its progress this way on 2026-11-01, #5775).

What changes

run_dedicated_inner runs each tick under catch_unwind. A panic ends the loop and stop_after_crash saves the levels, the maps, the scoreboard and the rest of the world state (save_game), then closes, and the process still exits with an error. The panic hook already writes the crash report.

It is not stop_dedicated, because the panic may have interrupted a swap the issue lists:

  • A guest's turn (as_guest): the game holds that player's state swapped in, and the guest's record in the hub is older. The record is marked not placed, so neither the player file nor the owner entry of level.dat is written from it: that guest keeps the file of the last autosave.
  • The hub taken out (self.lan.take() for the network tick): it is dropped by the unwind, so no player can be saved; the log says so. Other players' files are not written at all in that case.
  • Another dimension swapped in (enter_level): save_level and save_parked_levels save the level in place and the parked ones by their own dimension, so this case is saved as in a normal stop.

Verification

  • A real horizon-client --dedicated --nogui with a temporary panic! at tick 300 (not in the diff): it logged The server thread panicked: temporary test panic, wrote a crash report, logged Saving worlds and the three Saving chunks for level lines, and exited with status 1.
  • tools/parity.py dedicated_server: passes. pr_ready --quick: fmt, clippy, 1690 horizon-client tests, Python tests pass. A unit test reads the text of a &str, String and other panic payloads.

Not tested

A panic while a player is connected and mid-turn (the guest and hub cases above) is argued from the code, not run: it needs a client in the middle of a tick. lan_e2e does not inject a panic.

🤖 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/5952 **Author:** [@xFedeT](https://github.com/xFedeT) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/dedicated-crash-save` --- ### 📝 Commits (3) - [`b183f74`](https://github.com/horizon-rust/horizon/commit/b183f742574799072170d615553fbfa190383924) Dedicated server: a panic in the tick still saves the world, as runServer's finally does - [`8eff240`](https://github.com/horizon-rust/horizon/commit/8eff24080b3428dcbeece3ce31d5693f2ec89ba0) Dedicated server: test that a panic in a player's turn or with the hub out saves the world and no player file - [`010239c`](https://github.com/horizon-rust/horizon/commit/010239ced7c95691c77e1b8b91346e89b87529aa) Crash fixture: scan the guests only when HORIZON_CRASH_FIXTURE names the point ### 📊 Changes **3 files changed** (+278 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/dedicated.rs` (+106 -10) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+3 -0) ➕ `tools/test_dedicated_crash_save.py` (+169 -0) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Claude Sonnet 5.5), not by xFedeT personally. Closes #5788 as far as the issue asks: the world is saved after a panic. Player files are saved only when it is safe (below). ## What vanilla does `MinecraftServer.runServer` catches whatever the tick loop throws, writes the crash report, then calls `stopServer()`, which saves every player and every level. ## What was wrong A panic on the dedicated tick thread unwound out of `run_dedicated` without `stop_dedicated`: nothing since the last autosave was written (the official server lost its progress this way on 2026-11-01, #5775). ## What changes `run_dedicated_inner` runs each tick under `catch_unwind`. A panic ends the loop and `stop_after_crash` saves the levels, the maps, the scoreboard and the rest of the world state (`save_game`), then closes, and the process still exits with an error. The panic hook already writes the crash report. It is not `stop_dedicated`, because the panic may have interrupted a swap the issue lists: - **A guest's turn** (`as_guest`): the game holds that player's state swapped in, and the guest's record in the hub is older. The record is marked not placed, so neither the player file nor the owner entry of `level.dat` is written from it: that guest keeps the file of the last autosave. - **The hub taken out** (`self.lan.take()` for the network tick): it is dropped by the unwind, so no player can be saved; the log says so. Other players' files are not written at all in that case. - **Another dimension swapped in** (`enter_level`): `save_level` and `save_parked_levels` save the level in place and the parked ones by their own dimension, so this case is saved as in a normal stop. ## Verification - A real `horizon-client --dedicated --nogui` with a temporary `panic!` at tick 300 (not in the diff): it logged `The server thread panicked: temporary test panic`, wrote a crash report, logged `Saving worlds` and the three `Saving chunks for level` lines, and exited with status 1. - `tools/parity.py dedicated_server`: passes. `pr_ready --quick`: fmt, clippy, 1690 `horizon-client` tests, Python tests pass. A unit test reads the text of a `&str`, `String` and other panic payloads. ## Not tested A panic while a player is connected and mid-turn (the guest and hub cases above) is argued from the code, not run: it needs a client in the middle of a tick. `lan_e2e` does not inject a panic. 🤖 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:23:25 +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#6582
No description provided.