From 7e48131f677fd6e81134015f3757357581df6b8d Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Sat, 2 May 2026 23:44:18 +0200 Subject: [PATCH] fix: clear timeout on race settlement to prevent orphaned timers --- worker/src/scheduler.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/worker/src/scheduler.ts b/worker/src/scheduler.ts index 8786363..2de1f54 100644 --- a/worker/src/scheduler.ts +++ b/worker/src/scheduler.ts @@ -72,19 +72,20 @@ async function runCycle(): Promise { log.info({ accountCount: accounts.length }, "Processing accounts"); const results = await Promise.allSettled( - accounts.map((account) => - Promise.race([ + accounts.map((account) => { + let timer: ReturnType; + return Promise.race([ withTdlibMutex(account.phone, `ingest:${account.phone}`, () => runWorkerForAccount(account) ), - new Promise((_, reject) => - setTimeout( + new Promise((_, reject) => { + timer = setTimeout( () => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)), CYCLE_TIMEOUT_MS - ) - ), - ]) - ) + ); + }), + ]).finally(() => clearTimeout(timer)); + }) ); for (let i = 0; i < results.length; i++) {