@@ -782,6 +782,8 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume
782
782
783
783
private ConsumerRecords <K , V > pendingRecordsAfterError ;
784
784
785
+ private boolean pauseForPending ;
786
+
785
787
private volatile boolean consumerPaused ;
786
788
787
789
private volatile Thread consumerThread ;
@@ -1566,7 +1568,10 @@ private ConsumerRecords<K, V> doPoll() {
1566
1568
+ "after an error; emergency stop invoked to avoid message loss" , howManyRecords ));
1567
1569
KafkaMessageListenerContainer .this .emergencyStop .run ();
1568
1570
}
1569
- if (!isPartitionPaused (this .pendingRecordsAfterError .partitions ().iterator ().next ())) {
1571
+ TopicPartition firstPart = this .pendingRecordsAfterError .partitions ().iterator ().next ();
1572
+ boolean isPaused = isPartitionPauseRequested (firstPart );
1573
+ this .logger .debug (() -> "First pending after error: " + firstPart + "; paused: " + isPaused );
1574
+ if (!isPaused ) {
1570
1575
records = this .pendingRecordsAfterError ;
1571
1576
this .pendingRecordsAfterError = null ;
1572
1577
}
@@ -1682,10 +1687,11 @@ private void doPauseConsumerIfNecessary() {
1682
1687
this .logger .debug (() -> "Pausing for incomplete async acks: " + this .offsetsInThisBatch );
1683
1688
}
1684
1689
if (!this .consumerPaused && (isPaused () || this .pausedForAsyncAcks )
1685
- || this .pendingRecordsAfterError != null ) {
1690
+ || this .pauseForPending ) {
1686
1691
1687
1692
this .consumer .pause (this .consumer .assignment ());
1688
1693
this .consumerPaused = true ;
1694
+ this .pauseForPending = false ;
1689
1695
this .logger .debug (() -> "Paused consumption from: " + this .consumer .paused ());
1690
1696
publishConsumerPausedEvent (this .consumer .assignment ());
1691
1697
}
@@ -2385,6 +2391,7 @@ private void invokeBatchErrorHandler(final ConsumerRecords<K, V> records,
2385
2391
() -> invokeBatchOnMessageWithRecordsOrList (records , list ));
2386
2392
if (!afterHandling .isEmpty ()) {
2387
2393
this .pendingRecordsAfterError = afterHandling ;
2394
+ this .pauseForPending = true ;
2388
2395
}
2389
2396
}
2390
2397
}
@@ -2778,6 +2785,7 @@ private void invokeErrorHandler(final ConsumerRecord<K, V> record,
2778
2785
}
2779
2786
if (records .size () > 0 ) {
2780
2787
this .pendingRecordsAfterError = new ConsumerRecords <>(records );
2788
+ this .pauseForPending = true ;
2781
2789
}
2782
2790
}
2783
2791
}
0 commit comments