Skip to content

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

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

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!

@chengyixu
Copy link
Author

Hi team! Checking in — CI is passing and the fix is ready. Happy to make any changes needed to get this merged. Thanks!

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! This PR has been open for a few days with CI passing. The fix addresses the registry timeout issue (#2027). Would love to get a review when you have a moment. Happy to make any adjustments needed!

@chengyixu
Copy link
Author

Friendly ping — CI still passing, happy to rebase or address any feedback!

@chengyixu
Copy link
Author

Hi! Just a friendly check-in — CI is still passing. Ready to make any adjustments for merge. Thanks!

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! Friendly ping — PR #2054 adds a timeout to registry validation to prevent indefinite hangs. All 7 CI checks passing, SonarCloud green. This has been open since 2026-03-18. Would really appreciate a review. Thanks!

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! Checking in on this fix — adds AbortController timeout to prevent indefinite CLI hang when --registry-url is unreachable. All 7 CI checks are passing (SonarCloud green, Lint PR title passed). The fix directly addresses issue #2027 which is part of the 2026-04 bounty program. Would love a review when you have a moment. Thanks!

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! Checking in — this PR adds an AbortController timeout (5s) to prevent indefinite CLI hang when --registry-url points to an unreachable host. All 7 CI checks are passing and SonarCloud is green.

This directly addresses issue #2027 which is part of the 2026-04 Bounty Program (#2039). There are several competing PRs for the same issue — I'd love to hear if there's any specific feedback that would make this one the preferred fix. Happy to adjust the timeout duration, add tests, or make any other changes. Thanks!

@github-project-automation github-project-automation bot moved this from To Triage to Done in CLI - Kanban Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

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)

2 participants