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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user