diff --git a/Common/Server/Infrastructure/Semaphore.ts b/Common/Server/Infrastructure/Semaphore.ts index 50749d701f9..a1874d38d11 100644 --- a/Common/Server/Infrastructure/Semaphore.ts +++ b/Common/Server/Infrastructure/Semaphore.ts @@ -1,5 +1,5 @@ import Redis, { ClientType } from "./Redis"; -import { Mutex } from "redis-semaphore"; +import { Mutex, LockOptions } from "redis-semaphore"; export type SemaphoreMutex = Mutex; @@ -8,7 +8,8 @@ export default class Semaphore { public static async lock(data: { key: string; namespace: string; - lockTimeout?: number; + lockTimeout?: number | undefined; + acquireTimeout?: number | undefined; }): Promise { if (!data.lockTimeout) { data.lockTimeout = 5000; @@ -22,12 +23,20 @@ export default class Semaphore { throw new Error("Redis client is not connected"); } + const lockOptions: LockOptions = {}; + + if (data.lockTimeout) { + lockOptions.lockTimeout = data.lockTimeout; + } + + if (data.acquireTimeout) { + lockOptions.acquireTimeout = data.acquireTimeout; + } + const mutex: SemaphoreMutex = new Mutex( client, data.namespace + "-" + key, - { - lockTimeout: data.lockTimeout, - }, + lockOptions, ); await mutex.acquire(); diff --git a/ProbeIngest/API/Monitor.ts b/ProbeIngest/API/Monitor.ts index 4424a1ba7d1..1d9cd70f779 100644 --- a/ProbeIngest/API/Monitor.ts +++ b/ProbeIngest/API/Monitor.ts @@ -327,6 +327,8 @@ router.post( mutex = await Semaphore.lock({ key: probeId.toString(), namespace: "MonitorAPI.monitor-list", + lockTimeout: 15000, + acquireTimeout: 20000, }); } catch (err) { logger.error(err);