From 31885e41af77a1b9a808208ddbafeac2fc9e89f9 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Wed, 21 May 2025 10:52:11 +0700 Subject: [PATCH] [core] Use maxExecutionTime instead of timeout in async-lock to avoid "async-lock timed out in queue" error fix #831 --- src/core/abc/manager.abc.ts | 3 +-- src/core/engines/noweb/store/NowebPersistentStore.ts | 8 ++++++-- src/core/engines/noweb/useMultiFileAuthState.ts | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/abc/manager.abc.ts b/src/core/abc/manager.abc.ts index f80a0764..e5a4bbc2 100644 --- a/src/core/abc/manager.abc.ts +++ b/src/core/abc/manager.abc.ts @@ -50,7 +50,6 @@ export abstract class SessionManager WAIT_SESSION_RUNNING_TIMEOUT = 5_000; WAIT_STATUS_INTERVAL = 500; WAIT_STATUS_TIMEOUT = 10_000; - LOCK_TIMEOUT = 10_000; protected constructor( protected log: PinoLogger, @@ -59,7 +58,7 @@ export abstract class SessionManager ) { this.lock = new AsyncLock({ maxPending: Infinity, - timeout: this.LOCK_TIMEOUT, + maxExecutionTime: 30_000, }); this.log.setContext(SessionManager.name); } diff --git a/src/core/engines/noweb/store/NowebPersistentStore.ts b/src/core/engines/noweb/store/NowebPersistentStore.ts index 2762f5e0..79a7e8e4 100644 --- a/src/core/engines/noweb/store/NowebPersistentStore.ts +++ b/src/core/engines/noweb/store/NowebPersistentStore.ts @@ -50,7 +50,12 @@ export class NowebPersistentStore implements INowebStore { private labelsRepo: ILabelsRepository; private labelAssociationsRepo: ILabelAssociationRepository; public presences: any; - private lock: any; + + private lock: any = new AsyncLock({ + maxPending: Infinity, + maxExecutionTime: 60_000, + }); + private groupsFetchLock: any = new AsyncLock({ maxPending: Infinity, maxExecutionTime: 60_000, @@ -72,7 +77,6 @@ export class NowebPersistentStore implements INowebStore { this.labelsRepo = storage.getLabelsRepository(); this.labelAssociationsRepo = storage.getLabelAssociationRepository(); this.presences = {}; - this.lock = new AsyncLock({ maxPending: Infinity }); } init(): Promise { diff --git a/src/core/engines/noweb/useMultiFileAuthState.ts b/src/core/engines/noweb/useMultiFileAuthState.ts index e6ae5192..1d7bef4e 100644 --- a/src/core/engines/noweb/useMultiFileAuthState.ts +++ b/src/core/engines/noweb/useMultiFileAuthState.ts @@ -18,7 +18,10 @@ const AsyncLock = require('async-lock'); // https://github.com/nodejs/node/issues/26338 // Default pending is 1000, set it to infinity // https://github.com/rogierschouten/async-lock/issues/63 -const fileLock = new AsyncLock({ maxPending: Infinity }); +const fileLock = new AsyncLock({ + maxPending: Infinity, + maxExecutionTime: 30_000, +}); /** * stores the full authentication state in a single folder.