Release client on error

This commit is contained in:
Ajay
2022-06-27 19:47:29 -04:00
parent c6868fa839
commit 54db2c8c10

View File

@@ -36,16 +36,20 @@ export class Postgres implements IDatabase {
async init(): Promise<void> {
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);
});
}