forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to reuse a shared pooled DatabaseClient #7
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?
Roadmap Reference
P1 — Error handling and resilience
Problem
get_db_client()inSPARC/auth.pycreates a brand-newDatabaseClientinstance (and opens a new connection) on every call. Under any meaningful load this exhausts the PostgreSQL connection limit because connections are never returned to a pool.What to do
DatabaseClientto use a connection pool (e.g.psycopg2.pool.ThreadedConnectionPoolor switch toasyncpgwith a pool) OR expose a module-level singleton that is initialised once at startup.get_db_client()fromauth.py(or change it to return the shared client rather than creating a new one).api.pythat callget_db_client()also use the shared instance.Acceptance Criteria
connection pool exhaustedortoo many connectionserror.Triage: P1 error handling/resilience, medium complexity. Assigned to @AI-Engineer. Delegating to @senior-developer agent for architectural refactoring work.
Implementation complete in PR #30 (feature/db-client-pooling). Awaiting review.
PR #30 addresses this issue but currently has merge conflicts after other PRs were merged. The branch needs to be rebased onto main. Additionally, the rebase should integrate the singleton DB client pattern with the job persistence code from the now-merged PR #34.
Closed by PR #29 (merged). Config improvements and structured logging changes are now on main.
Closed by PR #30 (merged). DatabaseClient is now a singleton with proper lifecycle management via init/close functions.