Skip to content

fix: add timeout to registry validation to prevent indefinite hang#2054

Open
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/2027-registry-timeout
Open

fix: add timeout to registry validation to prevent indefinite hang#2054
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/2027-registry-timeout

Conversation

@chengyixu
Copy link

Summary

  • Add AbortController with 5-second timeout to registryValidation() to prevent CLI from hanging indefinitely when --registry-url points to an unreachable host
  • Switch from GET to HEAD for lightweight registry reachability check
  • Provide specific, actionable error messages for timeout vs general network failure
  • Clean up timer in finally block to prevent memory leaks
  • Add comprehensive unit tests (11 test cases) covering timeout, unreachable host, DNS failure, auth errors, and success scenarios

Root Cause

registryValidation() in src/utils/generate/registry.ts called fetch(registryUrl) without any timeout or AbortController. When targeting an unreachable host (e.g., 10.255.255.1), the TCP connection hangs indefinitely, blocking the CLI and stalling CI pipelines.

Changes

src/utils/generate/registry.ts:

  • Added AbortController with 5s timeout
  • Changed GETHEAD (lighter validation, only checks reachability)
  • Distinguished timeout errors from network errors with clear messages
  • Added finally block for timer cleanup

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

  • 11 test cases covering all failure modes and success paths

Test Plan

  • Existing tests pass
  • New tests cover timeout, abort, auth, network failure scenarios
  • Manual test: asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --registry-url http://10.255.255.1 now fails in ~5s with clear error

Fixes #2027

…syncapi#2027)

- Add AbortController with 5-second timeout to registryValidation()
- Switch from GET to HEAD for lightweight registry reachability check
- Provide specific error messages for timeout vs general network failure
- Clean up timer in finally block to prevent memory leaks
- Add comprehensive unit tests for all failure scenarios

Fixes asyncapi#2027
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 46f3225

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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link

@chengyixu
Copy link
Author

Hi team! Just checking in — all CI checks are passing (including SonarCloud Quality Gate) and the PR is mergeable. Would appreciate a review when you get a chance. Happy to address any feedback. Thanks!

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