Skip to content

fix: add timeout to registryValidation to prevent indefinite hang#2112

Open
armorbreak001 wants to merge 4 commits intoasyncapi:masterfrom
armorbreak001:bounty/2027-registry-timeout
Open

fix: add timeout to registryValidation to prevent indefinite hang#2112
armorbreak001 wants to merge 4 commits intoasyncapi:masterfrom
armorbreak001:bounty/2027-registry-timeout

Conversation

@armorbreak001
Copy link
Copy Markdown

Fixes #2027

Problem

registryValidation() in src/utils/generate/registry.ts uses fetch() with no timeout. When --registry-url points to an unreachable host (e.g., blackholed IP), the CLI hangs indefinitely.

Changes

  • Add AbortController with 5-second timeout to the fetch call
  • Use HTTP HEAD instead of GET for lighter weight registry validation
  • Detect AbortError and throw a clear timeout message: "Registry URL timed out after 5 seconds"
  • Preserve existing behavior for auth errors (401) and network errors

Testing

  • All existing unit tests pass (npm run unit:test)
  • Manual test: running with unreachable URL now fails fast with clear error instead of hanging

- Add 5-second timeout using AbortController to prevent indefinite hang
- Use HEAD request instead of GET for lighter validation
- Clear timeout error message for unreachable registries
- Fixes asyncapi#2027
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 12, 2026

🦋 Changeset detected

Latest commit: 5c580a9

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

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

- Test URL parser validation (empty, invalid, http, https)
- Test registry validation timeout behavior
- Covers the fix in asyncapi#2027
- Remove unnecessary 'as string' cast on registryUrl (SonarQube issue)
- Change 'error: any' to 'error: unknown' with instanceof guard
@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