forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to use a shared pooled database connection #430
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?
Summary
get_db_client()inauth.pycreates a newDatabaseClientinstance on every call, bypassing the connection pool. Under load this can exhaust available database connections.What to do
DatabaseClientmanages connections (inspectdatabase.pyor equivalent)get_db_client()to return a shared singleton or use a dependency-injected pooled client consistent with how the rest of the application accesses the databaseauth.pyAcceptance Criteria
get_db_client()returns the same shared client instance across requestsDatabaseClientis created per request inauth.pyReference
Roadmap: P1 - Error handling and resilience - get_db_client() connection pool bypass
Triage: Priority Wave 2 (Bug fix). Assigned to @AI-Engineer. Dispatching agent for implementation.
Resolution: Already implemented.
auth.pylines 149-178: Module-level_db_clientsingleton pattern.init_db_client()creates and connects the shared client at startup (called viaapi.pylifespan line 182).close_db_client()tears down on shutdown (called viaapi.pylifespan line 200).get_db_client()returns the singleton; only creates a new instance as a fallback (e.g., during tests).DatabaseClientinstantiation in auth endpoints.All acceptance criteria are met. Closing.