Skip to content

Commit 9e3d059

Browse files
committed
Stop postgres retries when over a threshold
1 parent 13ae468 commit 9e3d059

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ addDefaults(config, {
8989
max: 10,
9090
idleTimeoutMillis: 10000,
9191
maxTries: 3,
92-
fallbackOnFail: true
92+
fallbackOnFail: true,
93+
stopRetryThreshold: 800
9394
},
9495
dumpDatabase: {
9596
enabled: false,

src/databases/Postgres.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ export class Postgres implements IDatabase {
148148

149149
Logger.error(`prepare (postgres) try ${tries}: ${err}`);
150150
}
151-
} while (this.isReadQuery(type) && tries < maxTries());
151+
} while (this.isReadQuery(type) && tries < maxTries()
152+
&& this.activePostgresRequests < this.config.postgresReadOnly.stopRetryThreshold);
152153

153154
this.activePostgresRequests--;
154155
throw new Error(`prepare (postgres): ${type} ${query} failed after ${tries} tries`);

src/types/config.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
2121
weight: number;
2222
readTimeout: number;
2323
fallbackOnFail: boolean;
24+
stopRetryThreshold: number;
2425
}
2526

2627
export interface SBSConfig {

0 commit comments

Comments
 (0)