question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When using Promise.all to start connections, Kafka Broker times out

See original GitHub issue

I had some code that essentially started two Kafka consumers (each for different topics), when doing:

await Promise.all([
  consumer1.start(),
  consumer2.start()
])

I’d receive errors (via logs) about the Kafka broker being unable to be connected to, but only for one of the consumers.

Finally, I changed it to:

await consumer1.start()
await consumer2.start()

And everything worked as expected.

The consumer start() code is essentially just:

  async start() {
    await this.consumer.connect();
    await this.consumer.subscribe({
      topic: this.topic,
      fromBeginning: true
    });

    await this.consumer.run({
       // ....
    })
  }

My gut feeling on this is that there’s some sort of race condition triggered in the Broker connection code when starting multiple consumers (or potentially multiple consumers and producers) in parallel.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ThisIsMissEmcommented, Aug 28, 2019

Aha! Okay, yeah, increasing the connectionTimeout up to 10,000 helped, and the service started as expected. What’s a generally good amount of time to allow here? 1 second seems too low

On 28. Aug 2019, at 10:43, Túlio Ornelas notifications@github.com wrote:

I can see that you are not using authentication in your test environment, so the authenticationTimeout won’t be used. It’s common for a single broker to delay things a bit, try to increase the connectionTimeout, the default value is 1s.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tulios/kafkajs/issues/480?email_source=notifications&email_token=AAAHQ242XKII625SERMOTJTQGY3BVA5CNFSM4IPGVLU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5KLLYA#issuecomment-525645280, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAHQ2Y4JQW4R45C3KACMP3QGY3BVANCNFSM4IPGVLUQ.

1reaction
JaapRoodcommented, Aug 28, 2019

Having worked with time-outs before in previous deployments with other kafka clients: it should be less than the session timeout to prevent big issues, but network latency is definitely something to be tolerated too. We actually found 10s to be a good trade-off as well!

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Kafka.JS refuses to connect <<[BrokerPool] Failed ...
I was trying to reproduce the same issue. But this code is working fine with brokers: ['localhost:9092'] . There is no issue with...
Read more >
Kafka 3.3 Documentation
Apache Kafka can be started using ZooKeeper or KRaft. To get started with either configuration follow one the sections below but not both....
Read more >
Processing guarantees in Kafka - Medium
A system that provides no guarantee means any given message could be processed once, multiple times or not at all. With Kafka a...
Read more >
5 Common Pitfalls When Using Apache Kafka - Confluent
request.timeout.ms is a client-side configuration that defines how long the client (both producer and consumer) will wait to receive a response ...
Read more >
Client Configuration - KafkaJS
The request timeout can be disabled by setting enforceRequestTimeout to false . new Kafka({ clientId: 'my-app', brokers: ['kafka1:9092' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found