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

connection.failure event not emitted when state is disconnected #758

Closed
keith-chew opened this issue Mar 2, 2020 · 1 comment
Closed
Labels
stale Stale issues

Comments

@keith-chew
Copy link

keith-chew commented Mar 2, 2020

Environment Information

  • OS: Windows 10
  • Node Version: 10.16.3
  • NPM Version: 6.9.0
  • C++ Toolchain: Visual Studio
  • node-rdkafka version: 2.7.4

Steps to Reproduce
To test the reconnection robustness of our app, we have a simple test script which periodically enables/disables the firewall ports to kafka and DNS. This will check and ensure the app reconnects to kafka in the event of a network outage.

We listen to the connection.failure event and perform a retry:

  consumer.on("connection.failure", (err: any, metrics: any) => {
    // reconnect here
  });

Very rarely, the consumer will end up being disconnected and the event above is never called, which causes the app to stop consuming from the server. We tracked it down to the Client.prototype.connect method in lib\client.js:

  var fail = function(err) {
  ...
  if (self._isConnected) {
    ...
    self.emit('connection.failure', err, self.metrics);
  } else {
    next(err);
  }

If the connection happens to be disconnected, the connection.failure event will not be emitted. The fix would be to emit the event even when the state is disconnected:

  self.emit('connection.failure', err, self.metrics);
  next(err);

Our workaround at the moment is to register a callback to the connect() method and reconnect from there as well.

@stale
Copy link

stale bot commented May 31, 2020

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

@stale stale bot added the stale Stale issues label May 31, 2020
@stale stale bot closed this as completed Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues
Projects
None yet
Development

No branches or pull requests

1 participant