fix(highscores): bound service resource usage
The high-score endpoints previously accepted unbounded request bodies and ran SQLite work directly in async handlers, allowing oversized input or database contention to consume server resources. Add a 1 KiB route body limit, admit only one database operation at a time, shed excess requests with a clear 503, and run accepted SQLite work on blocking threads while retaining admission until that work finishes. Extend the Nginx example with matching request, connection, body, and proxy time limits, and cover the limits, health availability, contention, and cancellation behavior with tests. Test Plan: - `just --justfile tdkpin-rs/justfile test` -- passed (144 tests) - `just --justfile tdkpin-rs/justfile clippy` -- passed - `cargo +nightly fmt --manifest-path tdkpin-rs/highscore-server/Cargo.toml -- --check` -- passed - `rumdl check --flavor commonmark tdkpin-rs/highscore-server/README.md` -- passed - `git diff --cached --check` -- passed
This commit is contained in:
@@ -23,9 +23,12 @@ TDKPIN_HIGHSCORE_DB=/var/lib/tdkpin/highscores.sqlite3 \
|
||||
cargo run --manifest-path highscore-server/Cargo.toml
|
||||
```
|
||||
|
||||
Place [nginx.conf.example](nginx.conf.example) inside the public site's
|
||||
existing `server` block. The browser client expects the API at
|
||||
`/api/highscores` on the same origin as the game.
|
||||
Copy the rate and connection zone declarations from
|
||||
[nginx.conf.example](nginx.conf.example) into the existing `http` block, then
|
||||
place its two `location` blocks inside the public site's `server` block. The
|
||||
example bounds per-client and aggregate API traffic, request bodies, and proxy
|
||||
waits. The browser client expects the API at `/api/highscores` on the same
|
||||
origin as the game.
|
||||
|
||||
The crate inherits the parent [`rustfmt.toml`](../rustfmt.toml); run
|
||||
`just fmt-highscore-server` when formatting it directly.
|
||||
|
||||
Reference in New Issue
Block a user