Switch to axum and session-rs 0.2 with a health endpoint #2

Merged
selimaj-dev merged 1 commits from axum into master 2026-09-25 03:46:09 +00:00
Owner

Summary

  • Dependencies: session-rs 0.1.3 → 0.2.0 (only the axum feature), plus axum 0.8. Tokio's features are now listed explicitly instead of coming in through other crates.
  • Transport: the WebSocket is served on / through axum with Session::from_axum, with a 1 MiB limit per message and per frame. Clients connect to the same URL and speak the same wire format, so released clients are unaffected.
  • Health:
    • GET /health runs SELECT 1 and returns 200 ok, or 503.
    • server healthcheck probes it and exits with 0 or 1.
    • The Dockerfile HEALTHCHECK runs every 30 s, so no curl is needed in the image. Coolify reports it as the container's health, and compose.yaml is unchanged.
  • Shutdown: SIGTERM or Ctrl+C now stops the server gracefully. Before, the process (running as PID 1) ignored SIGTERM, so every stop or redeploy waited for Docker's 10-second SIGKILL.
  • Refactor: the RPC handlers are unchanged, only moved into register_handlers.

session-rs 0.2 also fixes these for the server:

  • unbounded frame allocation from a single crafted frame header
  • lost responses from the send-before-register race
  • session_loop exiting on an accept error
  • missing replies for unknown methods

Testing

Run locally, with a Python websockets client:

  • /health returns 200. A plain GET / returns 400, since it isn't an upgrade.
  • server healthcheck exits 0 when the server is up and 1 when nothing is listening.
  • get_player, auth with a bad token, set_cloak, send_player and an unknown method all return correct responses.
  • A 2 MiB message closes only that connection, and later connections are served.
  • SIGTERM with a WebSocket open exits in 0.05 s, and the client sees the close.

Not tested: the Docker image build and the HEALTHCHECK inside a container, because Docker wasn't available on the dev machine.

🤖 Generated with Claude Code

## Summary - **Dependencies:** `session-rs` 0.1.3 → 0.2.0 (only the `axum` feature), plus `axum` 0.8. Tokio's features are now listed explicitly instead of coming in through other crates. - **Transport:** the WebSocket is served on `/` through axum with `Session::from_axum`, with a 1 MiB limit per message and per frame. Clients connect to the same URL and speak the same wire format, so released clients are unaffected. - **Health:** - `GET /health` runs `SELECT 1` and returns 200 `ok`, or 503. - `server healthcheck` probes it and exits with 0 or 1. - The Dockerfile `HEALTHCHECK` runs every 30 s, so no curl is needed in the image. Coolify reports it as the container's health, and `compose.yaml` is unchanged. - **Shutdown:** SIGTERM or Ctrl+C now stops the server gracefully. Before, the process (running as PID 1) ignored SIGTERM, so every stop or redeploy waited for Docker's 10-second SIGKILL. - **Refactor:** the RPC handlers are unchanged, only moved into `register_handlers`. session-rs 0.2 also fixes these for the server: - unbounded frame allocation from a single crafted frame header - lost responses from the send-before-register race - `session_loop` exiting on an accept error - missing replies for unknown methods ## Testing Run locally, with a Python `websockets` client: - `/health` returns 200. A plain `GET /` returns 400, since it isn't an upgrade. - `server healthcheck` exits 0 when the server is up and 1 when nothing is listening. - `get_player`, `auth` with a bad token, `set_cloak`, `send_player` and an unknown method all return correct responses. - A 2 MiB message closes only that connection, and later connections are served. - SIGTERM with a WebSocket open exits in 0.05 s, and the client sees the close. **Not tested:** the Docker image build and the `HEALTHCHECK` inside a container, because Docker wasn't available on the dev machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
selimaj-dev added 1 commit 2026-09-25 03:44:17 +00:00
- Serve the session WebSocket on `/` through axum
  (`Session::from_axum`) with a 1 MiB message limit
- Add `/health` (checks the database) and a `server healthcheck`
  subcommand used by the Dockerfile HEALTHCHECK
- Shut down on SIGTERM/Ctrl+C so container stops are immediate
- Move per-connection handler registration into `register_handlers`

Co-Authored-By: Claude Opus 5.5 <[email protected]>
selimaj-dev merged commit b92358e9b6 into master 2026-09-25 03:46:09 +00:00
selimaj-dev deleted branch axum 2026-09-25 03:46:12 +00:00
Sign in to join this conversation.