mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 22:17:14 +03:00
Add timeout for all postgres requests
This commit is contained in:
@@ -77,7 +77,8 @@ addDefaults(config, {
|
|||||||
max: 10,
|
max: 10,
|
||||||
idleTimeoutMillis: 10000,
|
idleTimeoutMillis: 10000,
|
||||||
maxTries: 3,
|
maxTries: 3,
|
||||||
maxActiveRequests: 0
|
maxActiveRequests: 0,
|
||||||
|
timeout: 60000
|
||||||
},
|
},
|
||||||
postgresReadOnly: {
|
postgresReadOnly: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ export class Postgres implements IDatabase {
|
|||||||
pendingQueries.push(savePromiseState(lastPool.query({ text: query, values: params })));
|
pendingQueries.push(savePromiseState(lastPool.query({ text: query, values: params })));
|
||||||
const currentPromises = [...pendingQueries];
|
const currentPromises = [...pendingQueries];
|
||||||
if (options.useReplica && maxTries() - tries > 1) currentPromises.push(savePromiseState(timeoutPomise(this.config.postgresReadOnly.readTimeout)));
|
if (options.useReplica && maxTries() - tries > 1) currentPromises.push(savePromiseState(timeoutPomise(this.config.postgresReadOnly.readTimeout)));
|
||||||
|
else if (this.config.postgres.timeout) currentPromises.push(savePromiseState(timeoutPomise(this.config.postgres.timeout)));
|
||||||
const queryResult = await nextFulfilment(currentPromises);
|
const queryResult = await nextFulfilment(currentPromises);
|
||||||
|
|
||||||
this.activePostgresRequests--;
|
this.activePostgresRequests--;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface CustomPostgresConfig extends PoolConfig {
|
|||||||
|
|
||||||
export interface CustomWritePostgresConfig extends CustomPostgresConfig {
|
export interface CustomWritePostgresConfig extends CustomPostgresConfig {
|
||||||
maxActiveRequests: number;
|
maxActiveRequests: number;
|
||||||
|
timeout: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
|
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user