diff --git a/src/config.ts b/src/config.ts index 96d84d4..bbccfae 100644 --- a/src/config.ts +++ b/src/config.ts @@ -89,7 +89,8 @@ addDefaults(config, { max: 10, idleTimeoutMillis: 10000, maxTries: 3, - fallbackOnFail: true + fallbackOnFail: true, + stopRetryThreshold: 800 }, dumpDatabase: { enabled: false, diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index fab0fb1..161a9c9 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -148,7 +148,8 @@ export class Postgres implements IDatabase { Logger.error(`prepare (postgres) try ${tries}: ${err}`); } - } while (this.isReadQuery(type) && tries < maxTries()); + } while (this.isReadQuery(type) && tries < maxTries() + && this.activePostgresRequests < this.config.postgresReadOnly.stopRetryThreshold); this.activePostgresRequests--; throw new Error(`prepare (postgres): ${type} ${query} failed after ${tries} tries`); diff --git a/src/types/config.model.ts b/src/types/config.model.ts index e6b221d..c9ae96e 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -21,6 +21,7 @@ export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig { weight: number; readTimeout: number; fallbackOnFail: boolean; + stopRetryThreshold: number; } export interface SBSConfig {