Closed NilValue closed 3 years ago
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 :)
@NilValue You should check the milestones for scheduled release dates, or the Spring Calendar.
2.7.0-RC1 and 2.6.7 are currently scheduled for March 17.
@garyrussell Okay thank you very much :)
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.