Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-timeout-to-registry-url-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/cli": patch
---

fix: add timeout and AbortController to registry URL validation to prevent CLI hang on unreachable endpoints
28 changes: 28 additions & 0 deletions cli/src/utils/generate/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const REGISTRY_TIMEOUT_MS = 5000; // 5 seconds timeout for registry validation

export async function registryValidation(registryUrl: string): Promise<void> {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), REGISTRY_TIMEOUT_MS);

try {
await fetch(registryUrl, {
method: 'HEAD', // Use HEAD for a lightweight reachability check
signal: controller.signal,
});
} catch (error: any) { // Use 'any' for error type to handle both AbortError and other network errors
if (error.name === 'AbortError') {
throw new Error(
`Connection to registry URL '${registryUrl}' timed out after ${REGISTRY_TIMEOUT_MS / 1000} seconds. ` +
`Please ensure the URL is correct and the host is reachable.`
);
}
// Handle other network-related errors (e.g., DNS resolution failure, connection refused)
throw new Error(
`Failed to connect to registry URL '${registryUrl}'. ` +
`Network error: ${error.message}. ` +
`Please check your network connection and the provided registry URL.`
);
} finally {
clearTimeout(timeoutId);
}
}
Loading