Skip to content

Commit 1b45ce1

Browse files
committed
fix: add 10s timeout to registry URL validation to prevent indefinite hang
When --registry-url points to an unreachable host, the CLI hangs forever because fetch() has no timeout. Add AbortController with 10s timeout, switch to HEAD method, and provide distinct error messages for timeout vs other network failures. Closes #2027 https://claude.ai/code/session_01K5UYcnS3skK6SKhFz3dcZs
1 parent 32192aa commit 1b45ce1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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 timer = setTimeout(() => controller.abort(), 10000);
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+
});
1318
if (response.status === 401 && !registryAuth && !registryToken) {
1419
throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
1520
}
16-
} catch {
21+
} catch (error: unknown) {
22+
if (error instanceof Error && error.name === 'AbortError') {
23+
throw new Error(`Connection to registryURL timed out after 10s: ${registryUrl}`);
24+
}
1725
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
26+
} finally {
27+
clearTimeout(timer);
1828
}
1929
}

0 commit comments

Comments
 (0)