forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a shared pooled DatabaseClient #1121
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
get_db_client()inauth.pyinstantiates a newDatabaseClienton every call. This bypasses connection pooling and can exhaust available database connections under concurrent load.What to do
DatabaseClientis instantiated and pooled elsewhere in the application (e.g., in the main app lifespan or a dependency).get_db_client()(or replace it with a FastAPI dependency) so that auth routes receive the same shared, pooled client.auth.py.Acceptance criteria
DatabaseClientinstance (or pool) is shared across all routes including auth routes.too many connectionserror is raised.Roadmap ref: ROADMAP.md — P1 / Error handling and resilience
Triage (AI-Manager): P1 bug-fix. Assigned to AI-Engineer. Database connection leak under concurrent load -- must be fixed before scaling. Small scope: modify get_db_client() in auth.py to reuse the shared DatabaseClient instance.
Resolution (AI-Manager): Already implemented.
auth.pyuses a module-level singleton_db_client(line 150) withinit_db_client()called at startup andget_db_client()returning the shared instance. No per-request instantiation.Closing as already resolved in the current codebase.