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

Error handling on connection #117

Closed
AndrewKeig opened this issue Oct 29, 2014 · 30 comments
Closed

Error handling on connection #117

AndrewKeig opened this issue Oct 29, 2014 · 30 comments

Comments

@AndrewKeig
Copy link

Hi

I noticed a recent issue #103, which I think attempted to resolve this issue. When kafka is not available, or the host provided to kafka.client is wrong, how can I detect this? The error handlers in this example are never hit.. The example below creates a topic; it will not time out, and no error is reported; it simply repeats the process of trying to create a topic. If kafka fails for whatever reason we cannot recover on the application side, the application will never know.

var kafka = require('kafka-node'),
    Producer = kafka.Producer,
    client = new kafka.Client('wrong'),
    producer = new Producer(client);

    client.on('error', function (err) {
        console.log(err);
    });

    producer.on('error', function (err) {
        console.log(err);
    });

    producer.createTopics(['some-topic'], true, function (err, data) {
      console.log(data);
    });

@haio
Copy link
Member

haio commented Oct 29, 2014

Hi, do you get the same problem? For producer, every thing should be done after it get a ready event, which means client connect zookeeper and load broker info successfully. I also wonder why node-zookeeper-client doesn't emit any event even I give it a wrong connection string.

@AndrewKeig
Copy link
Author

Fair point, but it still just hangs if I add the ready event, and nothing is emitted. So I think your right its possibly zookeeper not emitting events.

var kafka = require('kafka-node'),
    Producer = kafka.Producer,
    client = new kafka.Client('127.0.0.1'),
    producer = new Producer(client);

    client.on('error', function (err) {
        console.log(err);
    });

    producer.on("ready", function () {

      producer.on('error', function (err) {
          console.log(err);
      });

      producer.createTopics(['some-topic'], true, function (err, data) {
        console.log(data);
      });
    });

@haio
Copy link
Member

haio commented Oct 29, 2014

Yeah, even I explicitly set a timeout option for zk, it still doesn't emit any event

@tekny
Copy link

tekny commented Nov 26, 2014

I've found that kafka-node works with zookeeper via ConnectionManager which will try to reconnect forever no matter what.

https://github.com/alexguan/node-zookeeper-client/blob/master/lib/ConnectionManager.js#L269

I assume it may be a serious design problem. IMO it should at least notify about those errors.

@alph486
Copy link

alph486 commented Feb 2, 2015

bump. I'm able to connect to a local Kafka instance via shell but the library will not. I'd love to debug but I don't get any notifications if ZK connect fails.

@mwaarna
Copy link

mwaarna commented Mar 3, 2015

bump!
This is a critical issue.

the on error event should be triggered or a new event added when connection fails.

Issue needs to be resolved in the Connection Manager:
alexguan/node-zookeeper-client#30

@perpective2410
Copy link

+1

2 similar comments
@reemdiab
Copy link

+1

@naderchehab
Copy link

+1

@estliberitas
Copy link
Contributor

Fix was proposed long long time ago and no changes since then: alexguan/node-zookeeper-client#16

@samypr100
Copy link

+1

2 similar comments
@Petrox
Copy link

Petrox commented Dec 19, 2016

+1

@codeofsumit
Copy link

+1

@Infra-dev
Copy link

+1

3 similar comments
@linxuanwei
Copy link

+1

@Insferatu
Copy link

+1

@danielnuriyev
Copy link

+1

@vivekpathak
Copy link

One way to handle this situation is to open a timeout with setTimeout before you send. The timeout would close the connection (and wait for callback) and then reconnect before calling send with the same parameters. This way you dont hang and come out even if kafka/zookeeper are down.

On the non error side, once the (original) send completes, the timeout should be cleared with clearTimeout because there is no need to resend.

It seems to work well when kafka/zk are up and recovers nicely from a restart.

@gnitsenko93
Copy link

@vivekpathak despite it is quite smart way this is still a workaround!

+1 for a native support

@respinha
Copy link

+1

3 similar comments
@ayZagen
Copy link

ayZagen commented Feb 28, 2018

+1

@benitojcv
Copy link

+1

@jean507
Copy link

jean507 commented May 27, 2018

+1

@AndrewKeig
Copy link
Author

AndrewKeig commented May 27, 2018

lol, 3 years and counting... I hear RabbitMQ is pretty good...

@jogaklaa
Copy link

+1

3 similar comments
@mihaimm
Copy link

mihaimm commented Jun 13, 2018

+1

@clodio
Copy link

clodio commented Jun 24, 2018

+1

@peterbabinec
Copy link

+1

@amirabiri
Copy link

@AndrewKeig - It's not related to Kafka. It's not even node. This library needs a lot of work still and it has many small gotchas. And at the same time for some reason no other alternative has emerged.

@AndrewKeig AndrewKeig closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2024
@vivekpathak
Copy link

One way to handle this situation is to open a timeout with setTimeout before you send. The timeout would close the connection (and wait for callback) and then reconnect before calling send with the same parameters. This way you dont hang and come out even if kafka/zookeeper are down.

On the non error side, once the (original) send completes, the timeout should be cleared with clearTimeout because there is no need to resend.

It seems to work well when kafka/zk are up and recovers nicely from a restart.

Workaround is robust even on planetary scale iot data transfer being done through kafka

Because its an underlying node library issue to do with one sided socket close, it should be Ok to use workaround (which can be considered to be the right way to do things since node socket close is one sided).

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

No branches or pull requests