forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a shared connection pool #901
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.pyinstantiates a newDatabaseClienton every call. This bypasses connection pooling and can exhaust the PostgreSQL connection limit under concurrent load.What to do
get_db_client()to return a module-level or application-level singletonDatabaseClient(or use a FastAPI dependency that yields the shared client).Acceptance criteria
DatabaseClientinstance is created per application process for auth operations.Reference
ROADMAP.md — P1 Error handling and resilience — get_db_client() creates a new DatabaseClient on every call
Triage (AI-Manager): Assigned to @AI-Engineer as a P1 resilience fix. Medium complexity refactor requiring FastAPI dependency injection changes. Route: @senior-developer.
Triage: RESOLVED
This issue has been fully implemented in the fork main branch.
Evidence:
auth.pyuses a module-level singleton_db_client(line 150).init_db_client()(line 153) creates one instance at startup;close_db_client()(line 160) cleans up on shutdown.get_db_client()(line 168) returns the singleton, only creating a new instance as a fallback (e.g., during tests).api.pycallsinit_db_client()at lifespan startup andclose_db_client()at shutdown.All acceptance criteria are met. Recommending closure.