Fix database connection pool leak in init_db()

init_db() was creating new pools without checking if one already exists,
causing "too many clients already" errors under load. Added early return
if pool is already initialized and set explicit pool limits (min=2, max=10).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-03 23:01:43 +00:00
parent 11bcafee55
commit bbcb79cc1e

View File

@@ -168,7 +168,9 @@ CREATE INDEX IF NOT EXISTS idx_friendly_names_latest ON friendly_names(actor_id,
async def init_db():
"""Initialize database connection pool and create schema."""
global pool
pool = await asyncpg.create_pool(DATABASE_URL)
if pool is not None:
return # Already initialized
pool = await asyncpg.create_pool(DATABASE_URL, min_size=2, max_size=10)
async with pool.acquire() as conn:
await conn.execute(SCHEMA_SQL)