An operator's `0` means "off", but SQLAlchemy gates recycling on
`_recycle > -1`, so a literal 0 recycles on every checkout: a fresh
connect and auth handshake per pool checkout. Mapping it to -1 is
therefore load-bearing, but doing it at the engine left the value
defined in `config` and corrected in `base_handler`, so a second
consumer could reasonably pass the raw constant and reintroduce the
footgun. Fold the mapping into the constant.
Also drop the `wait_timeout` figure the comment attributed to MariaDB.
Its default is 28800s; 600s is a value some hosts lower it to, not a
MariaDB one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The engine sets `pool_pre_ping` but no `pool_recycle`, so a connection
the database closed for being idle is still handed out, and the ping on
that half-closed socket blocks the worker until TCP gives up: tens of
seconds to minutes of an unresponsive API for every request that draws
it, while a fresh connection to the same server answers instantly.
Default to 300s, under the lowest `wait_timeout` MariaDB is commonly
configured with, and make it settable.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
As recommended by SQLAlchemy [1], this change makes a single
instantiation of the database engine and session maker, instead of one
entity per handler.
It also uses the provided `URL` constructor to better define the
database URL structure.
[1] https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage