open-webui/backend/open_webui/internal
Claude a03bde4701
fix(db): tighten aiosqlite terminate-shim install scope and worker wake-up
Address PR review findings on the original shim:

1. Source-shape gating (avoid shadowing future upstream fixes)
   The install now inspects the original implementation source and
   only patches when it actually references `self._connection.stop` —
   the buggy pattern this shim exists to fix. If a newer SQLAlchemy
   ships a working `_terminate_force_close` we leave it alone.

2. Wake the aiosqlite worker, don't just flag it
   In aiosqlite ≥0.20 the worker thread blocks on `_tx.get()`. Setting
   `_running = False` alone never unblocks it — the queue needs a
   sentinel push for the loop to observe the flag. The replacement
   now puts `(None, None)` onto `_tx` first and then flips
   `_running`, so the worker exits promptly instead of relying on a
   subsequent unrelated queue item or GC.

3. Conditional install (no global mutation on non-sqlite deployments)
   Move `_install_aiosqlite_compat()` inside the
   `if 'sqlite' in ASYNC_SQLALCHEMY_DATABASE_URL` branch in
   `internal/db.py`, so PostgreSQL / MySQL / etc. deployments get no
   SQLAlchemy monkey-patch at all.

https://claude.ai/code/session_01JSr4NZSskEUQvoJnavVXh8
2026-04-14 12:41:35 +00:00
..
migrations refac 2026-03-17 17:58:01 -05:00
_aiosqlite_compat.py fix(db): tighten aiosqlite terminate-shim install scope and worker wake-up 2026-04-14 12:41:35 +00:00
db.py fix(db): tighten aiosqlite terminate-shim install scope and worker wake-up 2026-04-14 12:41:35 +00:00
wrappers.py refac 2026-03-17 17:58:01 -05:00