From c008bdeca126062b2ab87bb82e7fc9ae05060e5f Mon Sep 17 00:00:00 2001 From: Pjotr Date: Sun, 8 Nov 2026 12:29:22 +0000 Subject: db: recover from a connection the server closed, and report the database Every database-backed endpoint 500'd with `CodecError { IO error: Broken pipe }` while the process answered /version quite happily. The cause was ours: `pool()` turns off the driver's `check_health` (a ping at checkout, dead connections replaced) to save a round trip -- sound against a database 130 ms away, worth nothing against loopback, and it costs the pool its self-healing. One server-side close of an idle session then becomes one failed request per dead socket: ten in a row, until a restart. * src/db.rs: `SQL_CHECK_HEALTH` (default true) decides the ping; `is_connection_loss` recognises the errors that mean the peer went away (broken pipe, reset, went away, lost connection, closed); `forget_pool` drops the cached pool so the next call rebuilds it; `health` probes reachability, cached ten seconds. One pool static shared by pool()/forget_pool (they had drifted into two). * src/error.rs (ApiError::from_db): on a connection loss, forget the pool -- the one place every database error passes through, so recovery does not depend on each caller. * src/lib.rs (/version): `"database": "reachable" | "unreachable"`; a service that answers while nothing behind it works is now visible. * src/config.rs: the switch, with the trade written down. * tests/db_recovery.rs: kills every pooled session from a second connection, then asserts the next twelve requests all succeed -- the scenario that produced the outage, now a regression test. * tests/...: unit test for the classifier (its own IO error text and the "this is a bad query, do not retry" cases). * README.md ("Database connections"), docs/www/operator-checklist.md: the knob, why it defaults on, and what /version reports. --- docs/www/operator-checklist.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'docs') diff --git a/docs/www/operator-checklist.md b/docs/www/operator-checklist.md index ed29456..14c5c82 100644 --- a/docs/www/operator-checklist.md +++ b/docs/www/operator-checklist.md @@ -195,6 +195,16 @@ is CPU-bound on the box, so rate-limit per token or keep the audience small — `limit_req` in the config is one way, but it keys on address, not token. +## Database connections + +`SQL_CHECK_HEALTH` (default `true`) makes the pool ping a connection at +checkout and replace it when the ping fails. Keep it on: without it, a +connection MariaDB closed while idle becomes a `500 database_error` on +whichever request draws it, one per dead socket, until the process +restarts — that is what happened on 2026-11-07. `GET /version` now carries +`"database": "reachable" | "unreachable"` (cached ten seconds), so an +up-but-useless service is visible without calling a data endpoint. + ## Plotting `POST /plot/rqtl` and `/plot/gemma` take a **posted mapping response** -- -- cgit 1.4.1