mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Don't fallback to db when too many redis connections
This commit is contained in:
parent
7aaf000d99
commit
d607d8b179
2 changed files with 9 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
import redis from "../utils/redis";
|
||||
import redis, { TooManyActiveConnectionsError } from "../utils/redis";
|
||||
import { Logger } from "../utils/logger";
|
||||
import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey, videoLabelsKey, videoLabelsHashKey, brandingHashKey, brandingKey } from "./redisKeys";
|
||||
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
|
@ -13,7 +13,11 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
|||
|
||||
return JSON.parse(reply);
|
||||
}
|
||||
} catch (e) { } //eslint-disable-line no-empty
|
||||
} catch (e) {
|
||||
if (e instanceof TooManyActiveConnectionsError) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const data = await fetchFromDB();
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ const writeResponseTime: number[] = [];
|
|||
let lastResponseTimeLimit = 0;
|
||||
const maxStoredTimes = 200;
|
||||
|
||||
export class TooManyActiveConnectionsError extends Error {}
|
||||
|
||||
export let connectionPromise = Promise.resolve();
|
||||
|
||||
if (config.redis?.enabled) {
|
||||
|
@ -61,7 +63,7 @@ if (config.redis?.enabled) {
|
|||
const getRead = readClient?.get?.bind(readClient);
|
||||
exportClient.get = (key) => new Promise((resolve, reject) => {
|
||||
if (config.redis.maxConnections && activeRequests > config.redis.maxConnections) {
|
||||
reject("Too many active requests in general");
|
||||
reject(new TooManyActiveConnectionsError("Too many active requests in general"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue