node-redis: ConnectionTimeoutError: Connection timeout
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
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 8
- Comments: 51
Hello,
We had this issue on our project. The root cause is that we try to
.connect(), and thenrequiremany node modules blocking the node loop with sync calls. The socket is blocked and the timeout is thrown. I suggest you to profile your applications to find if it’s the same kind of error.The fix here is to increase the timout of the socket as follow:
Has anyone here tried using the
pingIntervaloption?I am using node-redis (via redis-om) with Deno+Fresh, and a clean Redis Stack container running in a local Docker. Here’s what I did, it seems to have solved the issue for now. Hope this helps someone.
@leibale for me after several hours of debugging, it worked after I connect with the IP directly and increase the timeout to 50000 this is node-redis v4.6.1
Unfortunately i couldn’t resolve this issue I ended up using “ioredis” package instead!!
@eladitzhakian
works for me (the classic answer 😛)… wanna debug it together?
@menocomp great suggestion!
However, to my knowledge, I am not using a cluster and I therefore don’t think the solution applies to me 😦
I have also stumbled on to this only when using Jest (29) I have solved this in my unit tests by NOT mocking certain things
I feel like this is either a bug or rather a documentation issue.
For me as I want to migrate from v3 to v4 - I did get the timeout error as well, when I tried to use the official documentation like this:
But when I use the following code (with non-documented properties), the client does connect.
So I would argue, that the documentation is not listing tls, host and port as root properties correctly.
The above code was run in a node test project using redis version 4.6.7
So its a Jest problem. Specifically with the fake timers in any version > 27.
Have to use “legacy” now or everything locks up.
Adding
pingIntervalfixed read ETIMEDOUT error. Thanks@kabapy in order to catch this error you gave to handle
errorevents. This is not specific to this package, this is how node.js event emitter works. Just make sure to addclient.on('error', err => ...);Before calling
client.connectand the app won’t crash on timeout.BTW, there is already an issue + PR to add a note to the docs (https://github.com/redis/node-redis/issues/2302).
Got the may Be,
According to me this is issue because of race condition of async tasks. So to overcome that we can just go with await or we can connect to socket or server after
May be this solves issues then I am glad.
Running the command
node --inspect dist/app.jswith no issues indicates to me that there is a typescript compiler issue (perhaps fromts-node) going on in my case, moreso than it being an actual issue with redis.@aarhusgregersen All requires are sync. You can profile your application using chrome
about:inspectand nodejs--inspect-brkoption