Skip to content

Commit 2141743

Browse files
author
sungdark
committed
fix: add timeout and HEAD method to registry validation
Fixes #2027 - Added AbortController with 10 second timeout to prevent indefinite hangs - Changed from GET to HEAD request for lighter weight validation - Improved error messages to preserve original error and indicate timeout
1 parent 32192aa commit 2141743

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/utils/generate/registry.ts

Lines changed: 13 additions & 3 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 timeout = setTimeout(() => controller.abort(), 10_000); // 10 second timeout
1113
try {
12-
const response = await fetch(registryUrl as string);
14+
const response = await fetch(registryUrl as string, {
15+
method: 'HEAD',
16+
signal: controller.signal,
17+
});
18+
clearTimeout(timeout);
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 {
17-
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
22+
} catch (err: any) {
23+
clearTimeout(timeout);
24+
if (err.name === 'AbortError') {
25+
throw new Error(`Registry URL timed out after 10 seconds: ${registryUrl}`);
26+
}
27+
throw new Error(`Can't fetch registryURL: ${registryUrl}${err.message}`);
1828
}
1929
}

0 commit comments

Comments
 (0)