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

UnhandledPromiseRejection on connection error. #1664

Open
jan-osch opened this issue Mar 2, 2020 · 4 comments
Open

UnhandledPromiseRejection on connection error. #1664

jan-osch opened this issue Mar 2, 2020 · 4 comments
Labels

Comments

@jan-osch
Copy link

jan-osch commented Mar 2, 2020

I am getting an UnhandledPromiseRejectionWarning when ECONNREFUSED is thrown on initial connection.

const Queue = require('bull');

const q = new Queue('test', 'redis://localhost:8009'); // no redis instance here

q.on('error', e => console.error('Error event', e.message));

q.process('task', 1, (job) => {
  console.log('ok');
  return Promise.resolve(job.id);
})
 .catch(error => console.error('Failed to start consumer', error.message));

I am getting this output:

Error event connect ECONNREFUSED 127.0.0.1:8009
Error event Error initializing Lua scripts
Failed to start processing connect ECONNREFUSED 127.0.0.1:8009
(node:12173) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:8009
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
(node:12173) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12173) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error event connect ECONNREFUSED 127.0.0.1:8009
Error event connect ECONNREFUSED 127.0.0.1:8009

How can I handle the UnhandledPromiseRejectionWarning error ?

@jan-osch jan-osch changed the title UnhandledPromiseRejection with on connection error. UnhandledPromiseRejection on connection error. Mar 2, 2020
@cfey
Copy link

cfey commented Apr 1, 2020

Hi @jan-osch,
I got the same error
I fixed it by removing
global.Promise = require('bluebird');
This were declared somewhere in my project, without this global Promise override everything works as expected.

Let me know if this fixed your issue :)

Cheers

@jan-osch
Copy link
Author

jan-osch commented Apr 6, 2020

@cfey
Hey - thanks for checking that out. I don't override promises anywhere in the project. The sample code I provided is a single isolated file that I use to reproduce the issue.

I can confirm that the issue still exists.
Node version: v12.16.0
Bull 3.13.0

@stale
Copy link

stale bot commented Jul 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 12, 2021
@manast manast added bug and removed wontfix labels Jul 13, 2021
@lamai6
Copy link

lamai6 commented Jul 30, 2021

I still get this error but I find a (maybe ?) cleaner solution to fix that annoying warning by using Promise.

Solution

queue.isReady()
.then(() => {
    queue.process(function (job, done) {
        myFunction(...);
        done();
    });
})
.catch((err) => {
    console.error(`Error ${err.errno} : ${err.message}`);
    // If redis instance is not started, you can also stop your server
    // process.exit(1);
});

Result

If Redis instance is not started, instead of getting a UnhandledPromiseRejectionWarning, you will get an error in your console with my example :

github-bull-fix-unhandled

Versions

{
    "nodejs": "14.15.0",
    "bull": "3.27.0"
}

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

No branches or pull requests

4 participants