Skip to content

Commit dc6a38f

Browse files
committed
Fix Race with Delayed Idle
Defer setting the initial `lastReceive` until after the consumer is created. The `delayedIdleEvent()` test in `ConcurrentMessageListenerContainerMockTests` could fail because the event might be published a few milliseconds before the expected 500.
1 parent c7102f0 commit dc6a38f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ private final class ListenerConsumer implements SchedulingAwareRunnable, Consume
766766

767767
private boolean taskSchedulerExplicitlySet;
768768

769-
private long lastReceive = System.currentTimeMillis();
769+
private long lastReceive;
770770

771771
private long lastAlertAt = this.lastReceive;
772772

@@ -1299,6 +1299,7 @@ public void run() {
12991299
initAssignedPartitions();
13001300
publishConsumerStartedEvent();
13011301
Throwable exitThrowable = null;
1302+
this.lastReceive = System.currentTimeMillis();
13021303
while (isRunning()) {
13031304
try {
13041305
pollAndInvoke();

0 commit comments

Comments
 (0)