From c2acc6227b5820f0daffcf25b395dd99c8c2c788 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 27 Oct 2022 01:31:41 -0400 Subject: [PATCH] Don't kill program if can't connect to read server --- src/databases/Postgres.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index 161a9c9..db72021 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -53,19 +53,23 @@ export class Postgres implements IDatabase { }); if (this.config.postgresReadOnly && this.config.postgresReadOnly.enabled) { - this.poolRead = new Pool({ - ...this.config.postgresReadOnly - }); - this.poolRead.on("error", (err, client) => { - Logger.error(err.stack); - this.lastPoolReadFail = Date.now(); + try { + this.poolRead = new Pool({ + ...this.config.postgresReadOnly + }); + this.poolRead.on("error", (err, client) => { + Logger.error(err.stack); + this.lastPoolReadFail = Date.now(); - try { - client.release(true); - } catch (err) { - Logger.error(`poolRead (postgres): ${err}`); - } - }); + try { + client.release(true); + } catch (err) { + Logger.error(`poolRead (postgres): ${err}`); + } + }); + } catch (e) { + Logger.error(`poolRead (postgres): ${e}`); + } } if (!this.config.readOnly) {