When using Promise.all to start connections, Kafka Broker times out
See original GitHub issueI 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:
- Created 4 years ago
- Comments:10 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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!