You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This KafkaProducer automatically starts a new thread which runs in an infinite while loop until the producer is closed.
Right after, the KafkaProducer.initTransactions() method is called:
If the Kafka broker is not available, the initTransactions() method will throw a TimeoutException. As a result, this Producer is never closed and the aforementioned thread runs infinitely.
The application does not recover from this even if the Kafka broker comes back, because the DefaultKafkaProducerFactory is not aware of them. This results in "dead" threads running in the background.
Solution:
Make a try-catch for any RuntimeException around newProducer.initTransactions(). In the catch block, close the producer and rethrow the exception.
Thank you for the quick response and fix. This is amazing. Can I expect this fix to be included in 2.7.0-RC1? If so, when does it release? I want to remove my own workaround from our code base asap :)
I am using spring-kafka version: 2.6.3 (spring-boot-starter-parent:2.4.0) but the problem should be present in the current version as well.
Preconditions:
@Transactional
or with KafkaTemplate.executeInTransaction()Problem:
The DefaultKafkaProducerFactory will create a new KafkaProducer.
This KafkaProducer automatically starts a new thread which runs in an infinite while loop until the producer is closed.
Right after, the KafkaProducer.initTransactions() method is called:
If the Kafka broker is not available, the initTransactions() method will throw a TimeoutException. As a result, this Producer is never closed and the aforementioned thread runs infinitely.
The application does not recover from this even if the Kafka broker comes back, because the DefaultKafkaProducerFactory is not aware of them. This results in "dead" threads running in the background.
Solution:
Make a try-catch for any RuntimeException around newProducer.initTransactions(). In the catch block, close the producer and rethrow the exception.
The text was updated successfully, but these errors were encountered: