ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

Unhandled ETIMEDOUT error event is thrown even without listeners

Open Erreichl opened this issue 3 years ago • 6 comments

Hello there, we are using bull(mq)/redis for our queues. Recently our redis seems to be unreachable every other day for a few seconds. Now we are trying to prevent this error to crash our application. If I understood the documentation correctly, the error events should be emitted silently and not cause any harm.

We get these errors

[ioredis] Unhandled error event: Error: connect ETIMEDOUT
at processTimers (internal/timers.js:497:7)
at Socket.EventEmitter.emit (domain.js:483:12)
at Socket.emit (events.js:314:20)
at Object.onceWrapper (events.js:420:28)
at Socket.<anonymous> (/app/node_modules/ioredis/built/redis/index.js:317:37)
at processTimers (internal/timers.js:497:7)
Error: connect ETIMEDOUT
at Socket.<anonymous> (/app/node_modules/ioredis/built/redis/index.js:317:37)
at Socket.emit (events.js:314:20)
at Object.onceWrapper (events.js:420:28)
at Socket._onTimeout (net.js:483:8)
at RedisConnection.emit (events.js:314:20)

Until now, we were calling our redis just with the connection url.

new Redis(url)

After some investigation we tried to use reconnectOnError from this documentation. But we still get the error from above.

new Redis(url, {
  reconnectOnError (err) {
    const targetError = 'ETIMEDOUT'
    if (err.message.includes(targetError)) {
      return 1 
    }
  }
})

4.27.7 - is our ioredis version 12.19 - is our node version

Are we missing something? Is this a known issue? How can we prevent this error?

Thanks in advance Eric

Erreichl avatar Sep 14 '21 09:09 Erreichl

It's caused by timeouts at the connecting stage. You can try to increase the connectTimeout option. ioredis does emit errors silently. Isn't that what you've encountered?

luin avatar Sep 24 '21 01:09 luin

ioredis does emit errors silently. Isn't that what you've encountered?

No, I have noticed ETIMEDOUT crashes the whole process. I am on v5.3.1

psnehanshu avatar Aug 17 '23 09:08 psnehanshu

ioredis does emit errors silently. Isn't that what you've encountered?

No, I have noticed ETIMEDOUT crashes the whole process. I am on v5.3.1

Currently investigating the same issue, did you find a way to safely handle this? @pSnehanshu

tiagosiebler avatar Nov 10 '23 12:11 tiagosiebler

It has been a while, but I think just attaching listeners to error events fixed it.

psnehanshu avatar Nov 20 '23 05:11 psnehanshu

It has been a while, but I think just attaching listeners to error events fixed it.

Thanks for the reply! Found that too, seems to work nicely

tiagosiebler avatar Nov 20 '23 10:11 tiagosiebler

@pSnehanshu Could you give a code example how to solve it?

junoriosity avatar Dec 06 '23 21:12 junoriosity