Skip to content

Commit 3889b20

Browse files
committed
fix: add timeout handling to registryValidation fetch call
- Add AbortController with 5s timeout to prevent indefinite hangs - Switch from default GET to HEAD for lighter footprint - Clear timeout on success to avoid memory leaks - Add specific AbortError handling with descriptive message Fixes #2027
1 parent 2e6967c commit 3889b20

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/utils/generate/registry.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ export function registryURLParser(input?: string) {
88

99
export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) {
1010
if (!registryUrl) { return; }
11+
const controller = new AbortController();
12+
const timeoutId = setTimeout(() => controller.abort(), 5000);
1113
try {
12-
const response = await fetch(registryUrl as string);
14+
const response = await fetch(registryUrl as string, {
15+
signal: controller.signal,
16+
method: 'HEAD',
17+
});
18+
clearTimeout(timeoutId);
1319
if (response.status === 401 && !registryAuth && !registryToken) {
1420
throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
1521
}
16-
} catch {
22+
} catch (err: any) {
23+
clearTimeout(timeoutId);
24+
if (err.name === 'AbortError') {
25+
throw new Error(`Registry URL timed out after 5 seconds: ${registryUrl}`);
26+
}
1727
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
1828
}
1929
}

0 commit comments

Comments
 (0)