From cccbd44b53943979b44db702ea49ead7ff010659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20R=C3=B6sch?= Date: Tue, 5 Mar 2024 20:38:41 +0100 Subject: [PATCH] GH-3076: Set `batchFailed` in `ListenerConsumer` even if no `commonErrorHandler` Fixes: #3076 The `ListenerConsumer` sets `batchFailed` to `true` only if `commonErrorHandler` is provided * Move `this.batchFailed = true;` in the `doInvokeBatchListener()` before any error handling. # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java # spring-kafka/src/test/java/org/springframework/kafka/listener/TransactionalContainerTests.java (cherry picked from commit e4d9994a0396ac3871151ff0e98e5a9ea89c8dd5) --- .../kafka/listener/KafkaMessageListenerContainer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java b/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java index 092040b6e9..fec11852e4 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java @@ -160,6 +160,7 @@ * @author Francois Rosiere * @author Daniel Gentes * @author Soby Chacko + * @author Raphael Rösch */ public class KafkaMessageListenerContainer // NOSONAR line count extends AbstractMessageListenerContainer implements ConsumerPauseResumeEventPublisher { @@ -2313,13 +2314,13 @@ private RuntimeException doInvokeBatchListener(final ConsumerRecords recor } } catch (RuntimeException e) { + this.batchFailed = true; failureTimer(sample, null); batchInterceptAfter(records, e); if (this.commonErrorHandler == null) { throw e; } try { - this.batchFailed = true; invokeBatchErrorHandler(records, recordList, e); commitOffsetsIfNeededAfterHandlingError(records); }