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");
const results = await Promise.allSettled(
accounts.map((account) =>
Promise.race([
accounts.map((account) => {
let timer: ReturnType<typeof setTimeout>;
return Promise.race([
withTdlibMutex(account.phone, `ingest:${account.phone}`, () =>
runWorkerForAccount(account)
),
new Promise<never>((_, reject) =>
setTimeout(
new Promise<never>((_, 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++) {