Ir al contenido

Db Connection Not Closed (ARCH3084)

Esta página aún no está disponible en tu idioma.

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.

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
}
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.