Skip to content

fix: add timeout and error handling to registry URL validation#2095

Open
DragonBot00 wants to merge 2 commits intoasyncapi:masterfrom
DragonBot00:fix/registry-url-timeout
Open

fix: add timeout and error handling to registry URL validation#2095
DragonBot00 wants to merge 2 commits intoasyncapi:masterfrom
DragonBot00:fix/registry-url-timeout

Conversation

@DragonBot00
Copy link
Copy Markdown

Summary

Fixes #2027

The CLI hangs indefinitely when --registry-url points to an unreachable host because registryValidation() calls fetch() with no timeout or abort mechanism.

Changes

src/utils/generate/registry.ts:

  • Added AbortController with a 5-second timeout so unreachable hosts fail fast
  • Switched from GET to HEAD for lightweight URL validation (no need to download the full response body)
  • Surface descriptive error messages that distinguish between timeout vs. other network errors
  • Re-throw auth errors (401) correctly without masking them

test/unit/utils/registry.test.ts (new):

  • Unit tests for registryURLParser (valid/invalid URL formats)
  • Unit tests for registryValidation (timeout on unreachable host, error on invalid hostname)

Before (broken)

\
$ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --registry-url http://10.255.255.1

CLI hangs forever...

\\

After (fixed)

\
$ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --registry-url http://10.255.255.1
Error: Registry URL 'http://10.255.255.1' is unreachable (timed out after 5s). Please verify the URL is correct and accessible.
\\

- Add 5s timeout via AbortController to prevent CLI from hanging
  indefinitely when --registry-url points to an unreachable host
- Switch from GET to HEAD for lightweight URL validation
- Surface meaningful error messages for timeout vs network errors
- Add unit tests for registryURLParser and registryValidation

Fixes asyncapi#2027
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: 390adb3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[BUG] CLI hangs indefinitely when --registry-url points to an unreachable host (no timeout handling)

1 participant