-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
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]'
}
actraiser