forked from 0xWheatyz/SPARC
Fix: share a single pooled DatabaseClient instead of creating one per request in auth.py #1312
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 the connection pool and can exhaust the PostgreSQLmax_connectionslimit under even moderate load.What to do
get_db_client()to return a module-level (or application-lifespan-scoped) singletonDatabaseClient.auth.pywith that pattern.Acceptance criteria
DatabaseClientinstance is shared across all requests handled byauth.py.References
Roadmap: P1 Error handling and resilience — get_db_client() creates a new DatabaseClient on every call.
Already resolved.
SPARC/auth.pyuses a module-level singleton_db_clientwithinit_db_client()/close_db_client()/get_db_client().DatabaseClientindatabase.pyusespsycopg2.pool.ThreadedConnectionPool(min 2, max 10 connections).