Skip to content

Commit ea6cb66

Browse files
Add request timeout to waitForServer
Co-authored-by: jkingston <[email protected]>
1 parent 055c3db commit ea6cb66

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

injected/scripts/run-fake-extension.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ function run(cmd, args, opts = {}) {
3434
async function waitForServer(url, timeout = 30000, interval = 500) {
3535
const start = Date.now();
3636
while (Date.now() - start < timeout) {
37+
const remaining = timeout - (Date.now() - start);
38+
const controller = new AbortController();
39+
const requestTimeout = Math.max(100, Math.min(5000, remaining));
40+
const timer = setTimeout(() => controller.abort(), requestTimeout);
3741
try {
38-
const response = await fetch(url);
42+
const response = await fetch(url, { signal: controller.signal });
3943
if (response.ok) return;
4044
} catch {
4145
// Server not ready yet, continue polling
46+
} finally {
47+
clearTimeout(timer);
4248
}
4349
await new Promise((resolve) => setTimeout(resolve, interval));
4450
}

0 commit comments

Comments
 (0)