Files
open-webui-custom/backend/open_webui/utils
Classic298 3f133fad56 fix: release database connections immediately after auth instead of holding during LLM calls (#20545)
fix: release database connections immediately after auth instead of holding during LLM calls

Authentication was using Depends(get_session) which holds a database connection
for the entire request lifecycle. For chat completions, this meant connections
were held for 30-60 seconds while waiting for LLM responses, despite only needing
the connection for ~50ms of actual database work.

With a default pool of 15 connections, this limited concurrent chat users to ~15
before pool exhaustion and timeout errors:

    sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached,
    connection timed out, timeout 30.00

The fix removes Depends(get_session) from get_current_user. Each database
operation now manages its own short-lived session internally:

    BEFORE: One session held for entire request
    ──────────────────────────────────────────────────
    │ auth │ queries │ LLM wait (30s) │ save │
    │         CONNECTION HELD ENTIRE TIME            │
    ──────────────────────────────────────────────────

    AFTER: Short-lived sessions, released immediately
    ┌──────┐ ┌───────┐                 ┌──────┐
    │ auth │ │ query │   LLM (30s)     │ save │
    │ 10ms │ │ 20ms  │  NO CONNECTION  │ 20ms │
    └──────┘ └───────┘                 └──────┘

This is safe because:
- User model has no lazy-loaded relationships (all simple columns)
- Pydantic conversion (UserModel.model_validate) happens while session is open
- Returned object is pure Pydantic with no SQLAlchemy ties

Combined with the telemetry efficiency fix, this resolves connection pool
exhaustion for high-concurrency deployments, particularly on network-attached
databases like AWS Aurora where connection hold time is more impactful.
2026-01-10 15:34:36 +04:00
..
2025-12-30 18:28:57 +04:00
2025-10-26 19:33:39 -07:00
2025-12-01 10:59:01 -05:00
2025-09-17 00:49:44 -05:00
2026-01-09 02:46:04 +04:00
2025-12-22 00:39:05 +04:00
2025-12-29 00:21:18 +04:00
2025-11-04 13:30:59 -05:00
2026-01-01 01:51:37 +04:00
2026-01-09 22:21:00 +04:00
2025-12-22 09:45:55 +04:00
2026-01-05 03:46:46 +04:00
2026-01-01 14:01:18 +04:00
2025-10-25 23:01:13 -07:00
2026-01-03 18:43:12 +04:00
2025-12-02 03:52:38 -05:00
2025-07-18 06:11:53 +08:00
2024-11-30 23:36:30 -08:00
2026-01-09 22:21:00 +04:00
2026-01-08 00:42:29 +04:00