From bdc7dc7b2c11a10779f1ae11d5eaea80af06ced4 Mon Sep 17 00:00:00 2001 From: TeapoyY Date: Tue, 31 Mar 2026 16:44:36 +0800 Subject: [PATCH] fix: add timeout handling to registryValidation to prevent CLI hang When --registry-url points to an unreachable host, the CLI would hang indefinitely due to fetch() having no timeout. This fix: - Adds AbortController with a 5-second timeout - Uses clearTimeout to avoid memory leaks on successful fetch - Provides a clear error message when timeout occurs - Properly propagates the original error when fetch fails for other reasons Fixes #2027 --- src/utils/generate/registry.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/generate/registry.ts b/src/utils/generate/registry.ts index 16fdda2e5..0b2f6836e 100644 --- a/src/utils/generate/registry.ts +++ b/src/utils/generate/registry.ts @@ -8,12 +8,19 @@ export function registryURLParser(input?: string) { export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) { if (!registryUrl) { return; } + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 5000); try { - const response = await fetch(registryUrl as string); + const response = await fetch(registryUrl as string, { signal: controller.signal }); + clearTimeout(timeoutId); if (response.status === 401 && !registryAuth && !registryToken) { throw new Error('You Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken'); } - } catch { + } catch (error: any) { + clearTimeout(timeoutId); + if (error.name === 'AbortError') { + throw new Error(`Registry URL timed out after 5 seconds: ${registryUrl}`); + } throw new Error(`Can't fetch registryURL: ${registryUrl}`); } }