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

handleMessage seems to kill the process if a promise is rejected in the callback function #84

Closed
jcollum-cambia opened this issue Jul 11, 2017 · 5 comments
Assignees
Labels

Comments

@jcollum-cambia
Copy link

jcollum-cambia commented Jul 11, 2017

const Consumer = require('sqs-consumer');

const app = Consumer.create({
    queueUrl: config.aws.delta.queueUrl,
    handleMessage: (message, done) => {
      logger.debug(message);
      processor.process(message).then((result) => {
        logger.trace(`Message processed.`);
        done();
      }).catch((err) => {
        logger.error("Failed to handle message", message);
      // uncomment next line to get it to work without bailing  
      //done();
      });
    }
  });


... 
app.start();

If I uncomment done() then it will work. But I often want the message to stay on the queue -- maybe I couldn't connect to the database momentarily and that's why it failed. As the code is, if I hit that .catch and don't call done() the process mysteriously exits, even if I have an uncaughtException/unhandledRejection listener on the process.

"sqs-consumer": "^3.6.1",

Node 6

@Sicria
Copy link

Sicria commented Jul 13, 2017

Have you tried calling done(err); in your catch?

Calling done(err) with an error object will cause the message to be left on the queue.

@jcollum-cambia
Copy link
Author

That did it, thanks. Still there's the issue of not doing that crashing my process. No warnings/errors or anything, just a full stop.

@Sicria
Copy link

Sicria commented Jul 14, 2017

You could add this to catch any unhandled rejections that occur.

process.on('unhandledRejection', error => logger.crit('Unhandled Rejection', error));

@nspragg nspragg self-assigned this Jul 14, 2017
@nspragg
Copy link
Contributor

nspragg commented Jul 14, 2017

@Sicria - thanks for your suggestions.

@jcollum-cambia - "rejected in callback". Are you referring to an explicit call to reject or is an exception being thrown?

@nspragg
Copy link
Contributor

nspragg commented Jul 27, 2017

I'm closing this issue due to inactivity. Will reopen, if you wish to discuss further.

@nspragg nspragg closed this as completed Jul 27, 2017
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

3 participants