redis / node-redis

Redis Node.js client
https://redis.js.org/
MIT License
16.96k stars 1.89k forks source link

ConnectionTimeoutError: Connection timeout #1656

Closed younes-io closed 1 month ago

younes-io commented 3 years ago

I get this error and I don't understand why:

How do I get more details about this:

/mnt/c/dev/client-adapter/node_modules/redis/dist/lib/socket.js:157
            socket.setTimeout(__classPrivateFieldGet(this, _RedisSocket_options, "f").connectTimeout, () => socket.destroy(new errors_1.ConnectionTimeoutError()));
                                                                                                                           ^
ConnectionTimeoutError: Connection timeout
    at Socket.<anonymous> (/mnt/c/dev/client-adapter/node_modules/redis/dist/lib/socket.js:157:124)
    at Object.onceWrapper (node:events:513:28)
    at Socket.emit (node:events:394:28)
    at Socket.emit (node:domain:475:12)
    at Socket._onTimeout (node:net:486:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
[nodemon] app crashed - waiting for file changes before starting...

Environment

─❯ node -v 
v16.6.2

─❯ redis-server -v 
Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923

─❯ lsb_release -a   
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal
Thomaxius commented 1 year ago

This also happened for us when mocking time. For some reason the error only occurred in ci/cd server which has different timezone. This thread helped to figure out the following workaround:

this.clock = sinon.useFakeTimers({ now: DateTime.now().setZone('UTC').toMillis(), toFake: ['Date'], });

asish-tailwind commented 3 months ago

const client = redis.createClient({ socket: { host: hostName, port: 6380, tls: true }, password: azureKey, });

This works for me, I am using azure cache service - Redis version 6

insomnimus commented 1 month ago

Since Node 23.0, localhost seems to get translated as ::1 (IPV6), which caused this error for me. Specifying 127.0.0.1 did the trick but it's unfortunate that this happened at all.