Skip to content

Losing messages in RetryingBatchErrorHandler/ErrorHandlingUtils during rebalancing #2340

@vooft

Description

@vooft

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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions