Skip to content

fix: add timeout to registry URL validation to prevent indefinite hang#2082

Open
Islam0953 wants to merge 1 commit intoasyncapi:masterfrom
Islam0953:fix/registry-url-timeout
Open

fix: add timeout to registry URL validation to prevent indefinite hang#2082
Islam0953 wants to merge 1 commit intoasyncapi:masterfrom
Islam0953:fix/registry-url-timeout

Conversation

@Islam0953
Copy link
Copy Markdown

Description

Fixes #2027

The registryValidation() function calls fetch(registryUrl) with no timeout. When the URL points to an unreachable host (e.g., a black-holed IP like 10.255.255.1), the CLI hangs indefinitely waiting for the OS-level TCP timeout.

Changes

  • Added AbortController with 10-second timeout to the fetch call in registryValidation()
  • Switched HTTP method from GET to HEAD (only need to check reachability, not download body)
  • Added distinct error messages: timeout-specific vs generic network error
  • Added finally block to clean up the timer

How it works

const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 10000);
try {
  const response = await fetch(registryUrl, {
    method: 'HEAD',
    signal: controller.signal,
  });
  // ... existing auth check
} catch (error) {
  if (error.name === 'AbortError') {
    throw new Error(`Connection to registryURL timed out after 10s: ${registryUrl}`);
  }
  throw new Error(`Can't fetch registryURL: ${registryUrl}`);
} finally {
  clearTimeout(timer);
}

Testing

Tested with unreachable host — CLI now fails after 10 seconds with a clear error message instead of hanging indefinitely.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 25, 2026

⚠️ No Changeset found

Latest commit: 1b45ce1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Copy Markdown
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.

… hang

When --registry-url points to an unreachable host, the CLI hangs forever
because fetch() has no timeout. Add AbortController with 10s timeout,
switch to HEAD method, and provide distinct error messages for timeout
vs other network failures.

Closes asyncapi#2027

https://claude.ai/code/session_01K5UYcnS3skK6SKhFz3dcZs
@Islam0953 Islam0953 force-pushed the fix/registry-url-timeout branch from 37e0347 to 1b45ce1 Compare March 25, 2026 19:58
@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