forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a shared pooled DatabaseClient #927
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, bypassing the connection pool. Under load this will exhaust available database connections.Roadmap Reference
P1 Error handling and resilience -- get_db_client() creates a new DatabaseClient on every call (ROADMAP.md)
What to do
DatabaseClient/ connection pool is initialised (likely indatabase.pyormain.py).get_db_client()to return the shared instance (e.g. via a FastAPI dependency that yields the existing pool).auth.py.Acceptance criteria
DatabaseClientinstance exists at runtime (verifiable via a debug log or unit test mock).This issue has been resolved.
SPARC/auth.pynow uses a module-level singleton_db_clientwithinit_db_client(),close_db_client(), andget_db_client()functions that reuse a shared pooled DatabaseClient instead of creating new connections per request. Closing as completed.