question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redis connection error event handler is set ONLY after connection is established

See original GitHub issue

Bull Version: 1.40.1

const queue = new Queue('test', {
    connection: {
        host: 'localhost',
        port: 6379,
    },
});

queue.on('error', () => console.log('Something went wrong!'));

An unhandled error event is logged by IORedis when creating a new queue with no redis server available.

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

If there is a redis server available during the queue creation and somehow lost connection to the redis server, the queue will emit an error with Something went wrong!.

After some investigation, I found out that the error event hook is set after a initializing has been resolved. However, in the case where there is no redis server available during queue creation, it will be stuck in waitUntilReady promise and thus not setting the error event hook.

I will suggest to place the hook at here instead of after the initializing has been resolved. What you do think?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
manastcommented, Jul 29, 2021

That is quite strange considering there are 231 tests in total…

1reaction
YimingIsCOLDcommented, Jul 29, 2021

Alright! I will create a PR to address this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redis (ioredis) - Unable to catch connection error in order to ...
I've set lazyConnect to true in order to handle errors on the caller. But, when I define the url as localhoste:6379 (instead of...
Read more >
RedisConnectionException: No connection is available to ...
Connecting to it fails immediately despite the timeouts I've set. When I tried using an invalid host name and/or invalid port the timeouts...
Read more >
Error detection and handling with Redis - IBM Developer
When I initialize the ioredis library, a network connection is made, authentication credentials are exchanged, certificates are checked, and the ...
Read more >
Redis client handling
When Redis can't accept a new client connection because the maximum number of clients has been reached, it tries to send an error...
Read more >
The Proper Way To Connect Redis — Node.js | by Eren Yatkin
When we get an end event, timeout will start, then Redis will try to reconnect. We will wait until the timeout. setTimeout() will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found