Skip to content

Commit 3326b3c

Browse files
committed
fix(showcase/scripts): probeOg adds timeout + error logging
Without a timeout on the inner fetch, a hung upstream would stall the entire docs-probe run indefinitely (Node's fetch has no default timeout). Add a 10s AbortController. The bare catch also left 'error' states opaque — log URL + error kind so operators can tell an abort from DNS from TLS.
1 parent 5068852 commit 3326b3c

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

showcase/scripts/probe-docs.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ const NOINDEX_PATTERN =
7777

7878
async function probeOg(url: string | undefined): Promise<DocState> {
7979
if (!url) return "missing";
80+
// Hard timeout: without it, a hung upstream would stall the whole probe
81+
// run indefinitely (no default fetch timeout in Node). 10s is generous
82+
// enough for slow docs sites while still bounding CI cost.
83+
const controller = new AbortController();
84+
const timer = setTimeout(() => controller.abort(), 10_000);
8085
try {
81-
const res = await fetch(url, { method: "GET", redirect: "follow" });
86+
const res = await fetch(url, {
87+
method: "GET",
88+
redirect: "follow",
89+
signal: controller.signal,
90+
});
8291
if (res.status === 404) return "notfound";
8392
if (res.status < 200 || res.status >= 400) return "error";
8493
const matched = res.headers.get("x-matched-path") ?? "";
@@ -87,8 +96,16 @@ async function probeOg(url: string | undefined): Promise<DocState> {
8796
const body = await res.text();
8897
if (NOINDEX_PATTERN.test(body)) return "notfound";
8998
return "ok";
90-
} catch {
99+
} catch (err) {
100+
// Log the URL + kind so a spike of "error" states can be diagnosed
101+
// (abort vs. DNS vs. TLS). Silent returns made the output useless.
102+
const e = err as Error & { code?: string; cause?: { code?: string } };
103+
const code = e.code ?? e.cause?.code ?? "";
104+
const detail = code ? `${e.name}:${code}` : e.name;
105+
console.warn(`[probe-docs] probeOg failed ${url} (${detail}): ${e.message}`);
91106
return "error";
107+
} finally {
108+
clearTimeout(timer);
92109
}
93110
}
94111

0 commit comments

Comments
 (0)