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/warm-swans-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/cli": patch
---

fix: add 10s timeout to registry validation to prevent indefinite hang
10 changes: 8 additions & 2 deletions src/utils/generate/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
export async function registryValidation(registryUrl?: string, registryAuth?: string, registryToken?: string) {
if (!registryUrl) { return; }
try {
const response = await fetch(registryUrl as string);
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10000);
const response = await fetch(registryUrl as string, { signal: controller.signal });

Check warning on line 14 in src/utils/generate/registry.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This assertion is unnecessary since it does not change the type of the expression.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZz7p_OxjFzH0WTZ5ZxO&open=AZz7p_OxjFzH0WTZ5ZxO&pullRequest=2047
clearTimeout(timeout);
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) {
if (error.name === 'AbortError') {
throw new Error(`Registry URL timed out after 10s: ${registryUrl}. Check the URL or network connectivity.`);
}
throw new Error(`Can't fetch registryURL: ${registryUrl}`);
}
}
Loading