Skip to content

fix: add timeout to registry URL validation to prevent CLI hang (#2027)#2045

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

fix: add timeout to registry URL validation to prevent CLI hang (#2027)#2045
shengxinzhe wants to merge 2 commits intoasyncapi:masterfrom
shengxinzhe:fix/registry-url-timeout

Conversation

@shengxinzhe
Copy link

Summary

Fixes #2027

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

Problem

In src/utils/generate/registry.ts, registryValidation() calls fetch(registryUrl) without:

  • A timeout
  • An AbortController
  • Using a lightweight HTTP method

When the target host is unreachable (e.g., http://10.255.255.1), the TCP connection attempt hangs indefinitely, blocking the CLI and any CI pipeline using it.

Solution

  1. Added AbortController with 5-second timeout — The fetch call now aborts after 5 seconds if no response is received
  2. Switched from GET to HEAD — Only reachability needs to be checked, not content
  3. Clear timeout error message — Distinguishes timeout ("Registry URL timed out after 5s") from other fetch errors ("Can't fetch registryURL")
  4. Proper cleanupclearTimeout() in finally block prevents timer leaks

Changes Made

  • src/utils/generate/registry.ts — Added timeout + AbortController + HEAD method
  • test/unit/utils/registry.test.ts — New unit tests for both registryURLParser and registryValidation

Testing

  • Added unit tests covering:
    • registryURLParser(): undefined input, valid URLs, invalid URLs
    • registryValidation(): undefined input, unreachable host timeout, connection refused

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • No breaking changes — only adds timeout behavior
  • Unit tests added

When --registry-url points to an unreachable host, the CLI hangs
indefinitely because fetch() has no timeout or AbortController.

Changes:
- Add 5s timeout via AbortController to registryValidation()
- Use HEAD instead of GET for lightweight validation
- Provide clear error message distinguishing timeout from other errors
- Add unit tests for registryURLParser and registryValidation

Fixes asyncapi#2027
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: cf698d7

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

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