Db Connection Not Closed (ARCH3084)
هذا المحتوى غير متوفر بلغتك بعد.
Key typescript.performance.db-connection-not-closed · Severity error · Category performance
Opening a database connection/cursor and never releasing it drains the pool and eventually makes new requests wait for a connection and time out.
Incorrect
Section titled “Incorrect”async function count(): Promise<number> { const client = await pool.connect(); const res = await client.query("SELECT count(*) FROM users"); return res.rows[0].count; // client is never returned to the pool}Correct
Section titled “Correct”async function count(): Promise<number> { const client = await pool.connect(); try { const res = await client.query("SELECT count(*) FROM users"); return res.rows[0].count; } finally { client.release(); }}Return connections/cursors to the pool with release/close inside a try/finally.