Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to literal IPv6 addresses via the url option #2734

Open
TimWolla opened this issue Apr 4, 2024 · 0 comments
Open

Unable to connect to literal IPv6 addresses via the url option #2734

TimWolla opened this issue Apr 4, 2024 · 0 comments
Labels

Comments

@TimWolla
Copy link

TimWolla commented Apr 4, 2024

Description

When using the url option one cannot connect to IPv6 addresses:

let redis = require('redis');
let c = redis.createClient({ url: 'redis://[::1]:6379', socket: { reconnectStrategy: false } });

c.connect();

results in:

Error: getaddrinfo ENOTFOUND [::1]
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)

It works fine when passing the IPv6 address within the hostname:

let redis = require('redis');
let c = redis.createClient({ socket: { reconnectStrategy: false, hostname: '::1', port: 6379 } });

c.connect();

It worked fine with node-redis 3.x, but no longer works with node-redis 4.x. The issue is that the parse function from the url module stripped the square brackets, but the global URL constructor does not:

> require('url').parse('redis://[::1]:6379');
Url {
  protocol: 'redis:',
  slashes: true,
  auth: null,
  host: '[::1]:6379',
  port: '6379',
  hostname: '::1',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'redis://[::1]:6379/'
}
> new URL('redis://[::1]:6379')
URL {
  href: 'redis://[::1]:6379',
  origin: 'null',
  protocol: 'redis:',
  username: '',
  password: '',
  host: '[::1]:6379',
  hostname: '[::1]',
  port: '6379',
  pathname: '',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Node.js Version

v21.5.0

Redis Server Version

No response

Node Redis Version

4.6.13

Platform

Linux

Logs

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: getaddrinfo ENOTFOUND [::1]
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
Emitted 'error' event on Commander instance at:
    at RedisSocket.<anonymous> (/pwd/node_modules/@redis/client/dist/lib/client/index.js:412:14)
    at RedisSocket.emit (node:events:519:28)
    at RedisSocket._RedisSocket_shouldReconnect (/pwd/node_modules/@redis/client/dist/lib/client/socket.js:134:14)
    at RedisSocket._RedisSocket_connect (/pwd/node_modules/@redis/client/dist/lib/client/socket.js:162:117)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Commander.connect (/pwd/node_modules/@redis/client/dist/lib/client/index.js:185:9) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: '[::1]'
}
@TimWolla TimWolla added the Bug label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant