fix: clear timeout on race settlement to prevent orphaned timers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-05-02 23:44:18 +02:00
parent a79cb4749b
commit 7e48131f67

View File

@@ -72,19 +72,20 @@ async function runCycle(): Promise<void> {
log.info({ accountCount: accounts.length }, "Processing accounts"); log.info({ accountCount: accounts.length }, "Processing accounts");
const results = await Promise.allSettled( const results = await Promise.allSettled(
accounts.map((account) => accounts.map((account) => {
Promise.race([ let timer: ReturnType<typeof setTimeout>;
return Promise.race([
withTdlibMutex(account.phone, `ingest:${account.phone}`, () => withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
runWorkerForAccount(account) runWorkerForAccount(account)
), ),
new Promise<never>((_, reject) => new Promise<never>((_, reject) => {
setTimeout( timer = setTimeout(
() => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)), () => reject(new Error(`Account ${account.phone} ingestion timed out after ${CYCLE_TIMEOUT_MS / 60_000}min`)),
CYCLE_TIMEOUT_MS CYCLE_TIMEOUT_MS
) );
), }),
]) ]).finally(() => clearTimeout(timer));
) })
); );
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {