-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
In what version(s) of Spring for Apache Kafka are you seeing this issue?
For example:
2.3.7+ (since introduction of RetryingBatchErrorHandler
)
Describe the bug
If a listener doing a retry and rebalancing kicks in, then the consumer will be unpaused and every keep-alive consumer.poll()
invocation in the error handler will start returning records and the error handler will throw them away.
spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/listener/ErrorHandlingUtils.java
Line 69 in e4d9641
consumer.poll(Duration.ZERO); |
consumer.pause(consumer.assignment());
try {
while (nextBackOff != BackOffExecution.STOP) {
consumer.poll(Duration.ZERO); // after rebalancing this poll will start returning records
try {
...
It seems that the rebalancing listener KafkaMessageListenerContainer
can re-pause the consumer again, but it is not aware that the error handler paused it.
To Reproduce
Create a listener with infinite retry RetryingBatchErrorHandler
that will be constantly failing and force rebalancing. After rebalancing finished RetryingBatchErrorHandler
will drain all the messages from assigned partitions without any processing.
Expected behavior
RetryingBatchErrorHandler should re-pause consumer after rebalancing.
Sample
Test is using RetryingBatchErrorHandler
, but logic in ErrorHandlingUtils
is essentially the same
https://github.com/vooft/kafka-retry-issue/blob/master/src/test/java/com/example/kafkaissue/KafkaIssueTest.java