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

Unhandled 'error' event terminates node.js process #531

Closed
snmgian opened this issue Dec 8, 2016 · 1 comment
Closed

Unhandled 'error' event terminates node.js process #531

snmgian opened this issue Dec 8, 2016 · 1 comment
Labels

Comments

@snmgian
Copy link

snmgian commented Dec 8, 2016

After stopping a kafka instance (I have 2 running instances under normal conditions), node prints the following output and then terminates the process:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:9093
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1081:14)

I attached 'error' event handlers on all the Client, Offset and Consumer objects that I've manually instantiated.

If I setup a global error handler, then the process doesn't terminate and the consumer happily continues receiving messages from the remaining broker.

process.on('uncaughtException', (err) => {
  console.log('whoops! there was an error', err.stack);
});

In Client#fetchLatestOffsets (the app is invoking this method) there are the following lines:
https://github.com/SOHU-Co/kafka-node/blob/master/lib/offset.js#L91

      var offset = new Offset(client);
      offset.fetch(payloads, callback);

So, it creates an internal new Offset object, that newly offset has not attached an 'error' event handler, so when Client emits an error it aborts the process because the offset re-emits the event but no one is listening to it.

https://github.com/SOHU-Co/kafka-node/blob/master/lib/offset.js#L18

var Offset = function (client) {
  var self = this;
  // ... 
  this.client.on('error', function (err) {
    self.emit('error', err);
  });
};

The solution seems to be to not create a new Offset and just invoke self.fetch(...), or don't re-emit Client error events forcing the user to handle those events with Client#on.

This problem does not occur if I don't invoke Offset#fetchLatestOffsets. I'm using v1.0.7

Any thoughts?

@hyperlink
Copy link
Collaborator

I would lean towards using the self.fetch but I'm not sure why a one time instance of Offset is created. Maybe @CharlesWall recalls?

@hyperlink hyperlink added the bug label Dec 10, 2016
hyperlink added a commit that referenced this issue Jan 3, 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

2 participants