Skip to content

Conversation

@JustMaier
Copy link

Fixes #1145

Problem

Many modern dev servers (Node.js v18+) bind to IPv6 by default. When a service only listens on [::1]:3001, the REST Client fails with:

ECONNREFUSED 127.0.0.1:3001

Solution

Add IPv6-preferred DNS resolution for localhost requests. The extension now:

  1. Checks for both IPv6 (::1) and IPv4 (127.0.0.1) addresses
  2. Prefers IPv6 when available
  3. Falls back to IPv4 for compatibility

Changes

  • Modified src/utils/httpClient.ts (lines 189-227)
  • Added custom HTTP/HTTPS agent for localhost only
  • No breaking changes, no new dependencies

Testing

Works with:

  • ✅ IPv6-only services ([::1]:3001)
  • ✅ IPv4-only services (127.0.0.1:3001)
  • ✅ Dual-stack services (both)

The fix matches browser behavior for localhost connections.

Fixes connectivity issues when services are listening on IPv6 loopback
addresses (::1) by implementing IPv6-preferred DNS resolution for localhost.

Changes:
- Add custom HTTP/HTTPS agent for localhost that prefers IPv6 addresses
- Implement DNS lookup that checks both IPv6 and IPv4, preferring IPv6
- Automatic fallback to IPv4 when IPv6 is not available

The fix ensures the REST Client can connect to services regardless of
whether they're bound to IPv4 (127.0.0.1), IPv6 (::1), or both.

Fixes Huachao#1145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ECONNREFUSED - Connection was Rejected

1 participant