Add statement timeout for read

This commit is contained in:
Ajay 2022-07-22 16:39:31 -04:00
parent 603bad4967
commit b616ac990b

View file

@ -50,7 +50,10 @@ export class Postgres implements IDatabase {
});
if (this.config.postgresReadOnly && this.config.postgresReadOnly.enabled) {
this.poolRead = new Pool(this.config.postgresReadOnly);
this.poolRead = new Pool({
...this.config.postgresReadOnly,
statement_timeout: 120
});
this.poolRead.on("error", (err, client) => {
Logger.error(err.stack);
this.lastPoolReadFail = Date.now();
@ -119,9 +122,7 @@ export class Postgres implements IDatabase {
}
}
} catch (err) {
if (err instanceof Error && err.message.includes("terminating connection due to conflict with recovery")) {
options.useReplica = false;
}
options.useReplica = false;
Logger.error(`prepare (postgres) try ${tries}: ${err}`);
}