[PR #2116] [MERGED] Save the world on SIGTERM, Ctrl+C and SIGHUP #4019

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2116
Author: @kacpherek
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: fix/2095-signal-save


📝 Commits (2)

  • 2659654 Save the world when the game gets SIGTERM, Ctrl+C or SIGHUP, and disconnect on native quit
  • 739d4fe Merge main into fix/2095-signal-save

📊 Changes

2 files changed (+54 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+22 -0)
📝 crates/horizon-threads/src/lib.rs (+32 -0)

📄 Description

What and why

Killing the game with SIGTERM, Ctrl+C or SIGHUP (macOS and Linux) ended it at once without saving. Vanilla saves, because its JVM shutdown hook halts the integrated server on those signals.

Cause: horizon-client installed no signal handler, so the default action killed the process. Only horizon-server's supervisor had one.

Fix:

  • horizon_threads::catch_stop_signals (the crate that already holds the few unsafe OS calls) counts SIGINT, SIGTERM and SIGHUP. A second request ends the process at once, so a stuck save can still be killed.
  • Game::about_to_wait turns the first request into the same quit as a window close (begin_closing_save(true)), so the server thread saves the world and the lock is released. While still loading, with no world open, it just exits.
  • On a native quit (Cmd+Q) in a remote world, save_for_exit now closes the connection like leave_server does, so the host sees a clean leave instead of a dropped socket.

How I saw the bug with the test build: opened a world, placed a block with c command setblock ..., sent kill -TERM to the game process. It exited within a second, the chunk with the new block had no region file, and session.lock was left behind.

Not done here: a timed shutdown watchdog (vanilla's ClientShutdownWatchdog), the leave_game statistic in single player, and surfacing save errors on native quit.

Fixes #2095.

Vanilla reference

  • Main.java, "Client Shutdown Thread": halts the integrated server when the JVM shuts down, which also runs on SIGTERM and SIGINT.
  • Minecraft.stop / Minecraft.disconnect: a window close saves and closes the connection.

Self-check

cargo check -p horizon-client passes.


🔄 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/2116 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/2095-signal-save` --- ### 📝 Commits (2) - [`2659654`](https://github.com/horizon-rust/horizon/commit/265965445d471e0dedba02d998362e8642443b78) Save the world when the game gets SIGTERM, Ctrl+C or SIGHUP, and disconnect on native quit - [`739d4fe`](https://github.com/horizon-rust/horizon/commit/739d4fe1871b5028e70e781afe55f395a453288e) Merge main into fix/2095-signal-save ### 📊 Changes **2 files changed** (+54 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+22 -0) 📝 `crates/horizon-threads/src/lib.rs` (+32 -0) </details> ### 📄 Description ## What and why Killing the game with SIGTERM, Ctrl+C or SIGHUP (macOS and Linux) ended it at once without saving. Vanilla saves, because its JVM shutdown hook halts the integrated server on those signals. Cause: `horizon-client` installed no signal handler, so the default action killed the process. Only `horizon-server`'s supervisor had one. Fix: - `horizon_threads::catch_stop_signals` (the crate that already holds the few unsafe OS calls) counts SIGINT, SIGTERM and SIGHUP. A second request ends the process at once, so a stuck save can still be killed. - `Game::about_to_wait` turns the first request into the same quit as a window close (`begin_closing_save(true)`), so the server thread saves the world and the lock is released. While still loading, with no world open, it just exits. - On a native quit (Cmd+Q) in a remote world, `save_for_exit` now closes the connection like `leave_server` does, so the host sees a clean leave instead of a dropped socket. How I saw the bug with the test build: opened a world, placed a block with `c command setblock ...`, sent `kill -TERM` to the game process. It exited within a second, the chunk with the new block had no region file, and `session.lock` was left behind. Not done here: a timed shutdown watchdog (vanilla's `ClientShutdownWatchdog`), the `leave_game` statistic in single player, and surfacing save errors on native quit. Fixes #2095. ## Vanilla reference - `Main.java`, "Client Shutdown Thread": halts the integrated server when the JVM shuts down, which also runs on SIGTERM and SIGINT. - `Minecraft.stop` / `Minecraft.disconnect`: a window close saves and closes the connection. ## Self-check `cargo check -p horizon-client` passes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:14:03 +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#4019
No description provided.