fix: clear timeout timer in runSource to prevent event loop hang
The Promise.race timeout was never cleared on success/failure, keeping the Node event loop alive for ~30s after fast sweeps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,15 +47,18 @@ const SOURCE_TIMEOUT_MS = 30_000; // 30s max per individual source
|
|||||||
|
|
||||||
export async function runSource(name, fn, ...args) {
|
export async function runSource(name, fn, ...args) {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
let timer;
|
||||||
try {
|
try {
|
||||||
const dataPromise = fn(...args);
|
const dataPromise = fn(...args);
|
||||||
const timeoutPromise = new Promise((_, reject) =>
|
const timeoutPromise = new Promise((_, reject) => {
|
||||||
setTimeout(() => reject(new Error(`Source ${name} timed out after ${SOURCE_TIMEOUT_MS / 1000}s`)), SOURCE_TIMEOUT_MS)
|
timer = setTimeout(() => reject(new Error(`Source ${name} timed out after ${SOURCE_TIMEOUT_MS / 1000}s`)), SOURCE_TIMEOUT_MS);
|
||||||
);
|
});
|
||||||
const data = await Promise.race([dataPromise, timeoutPromise]);
|
const data = await Promise.race([dataPromise, timeoutPromise]);
|
||||||
return { name, status: 'ok', durationMs: Date.now() - start, data };
|
return { name, status: 'ok', durationMs: Date.now() - start, data };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return { name, status: 'error', durationMs: Date.now() - start, error: e.message };
|
return { name, status: 'error', durationMs: Date.now() - start, error: e.message };
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user