From 54db2c8c10b2c06314c9379ccde8a199679a78bd Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 27 Jun 2022 19:47:29 -0400 Subject: [PATCH] Release client on error --- src/databases/Postgres.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index 51b9fdb..1d5cb5e 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -36,16 +36,20 @@ export class Postgres implements IDatabase { async init(): Promise { this.pool = new Pool(this.config.postgres); - this.pool.on("error", (err) => { + this.pool.on("error", (err, client) => { Logger.error(err.stack); this.lastPoolFail = Date.now(); + + client.release(true); }); if (this.config.postgresReadOnly) { this.poolRead = new Pool(this.config.postgresReadOnly); - this.poolRead.on("error", (err) => { + this.poolRead.on("error", (err, client) => { Logger.error(err.stack); this.lastPoolReadFail = Date.now(); + + client.release(true); }); }