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

ioredis won't throw errors, prints to console instead - Unhandled error event: Error: connect ECONNREFUSED #1235

Closed
vktrl opened this issue Nov 10, 2020 · 6 comments

Comments

@vktrl
Copy link

vktrl commented Nov 10, 2020

Error handling seems to be broken when trying to query a non-existent database. To reproduce:

const Redis = require('ioredis');

const settings = {
  host: "localhost",
  port: 1234 // any invalid port
};

const redis = new Redis(settings);

(async function() {
  try {
    await redis.info()
  } catch (err) {
    // no error is caught, ioredis prints straight to console
    console.log("caught: ", err)
  }
})()

Results in console getting flooded with:

[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)

Version 4.19.2

@peteraw77
Copy link

Experiencing the same issue, tried passing a reconnectOnError function but no use

@peteraw77
Copy link

The proposed solution in #1209 seemed to resolve this for me.

@vktrl
Copy link
Author

vktrl commented Nov 10, 2020

The proposed solution in #1209 seemed to resolve this for me.

I don't see how this helps. Ioredis should throw an error so I could do something about it.

@smartinio
Copy link

@vktrl Redis extends EventEmitter, so it doesn't throw the error. It emits the error. You need to attach an error handler using e.g:

redis.on('error', (e) => doSomething())

@vktrl
Copy link
Author

vktrl commented Nov 11, 2020

@vktrl Redis extends EventEmitter, so it doesn't throw the error. It emits the error. You need to attach an error handler using e.g:

redis.on('error', (e) => doSomething())

Oh, I see, thanks!

@cope
Copy link

cope commented Oct 8, 2021

And what can we do in redis.on('error' to make this stop? I tried .disconnect and .quit and nothing helps 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants