Skip to content

Commit ea87440

Browse files
garyrussellartembilan
authored andcommitted
GH-2627: Deadlock on lifecycleMonitor Regression
Resolves #2627 Introduced by 73bee66 Remove the synchronization; it was added because an earlier implementation referenced `containers` which can only be used under the lock. When the implementation changed, I failed to remove the unnecessary sync. **cherry-pick to 2.9.x**
1 parent 00afc59 commit ea87440

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,22 @@ protected void doStop(final Runnable callback, boolean normal) {
352352

353353
@Override
354354
public void childStopped(MessageListenerContainer child, Reason reason) {
355-
synchronized (this.lifecycleMonitor) {
356-
if (this.reason == null || reason.equals(Reason.AUTH)) {
357-
this.reason = reason;
358-
}
359-
if (Reason.AUTH.equals(this.reason)
360-
&& getContainerProperties().isRestartAfterAuthExceptions()
361-
&& this.concurrency == this.stoppedContainers.incrementAndGet()) {
355+
if (this.reason == null || reason.equals(Reason.AUTH)) {
356+
this.reason = reason;
357+
}
358+
if (Reason.AUTH.equals(this.reason)
359+
&& getContainerProperties().isRestartAfterAuthExceptions()
360+
&& this.concurrency == this.stoppedContainers.incrementAndGet()) {
361+
362+
this.reason = null;
363+
this.stoppedContainers.set(0);
362364

363-
this.reason = null;
364-
this.stoppedContainers.set(0);
365-
doStart();
365+
// This has to run on another thread to avoid a deadlock on lifecycleMonitor
366+
AsyncTaskExecutor exec = getContainerProperties().getListenerTaskExecutor();
367+
if (exec == null) {
368+
exec = new SimpleAsyncTaskExecutor(getListenerId() + ".authRestart");
366369
}
370+
exec.execute(() -> start());
367371
}
368372
}
369373

0 commit comments

Comments
 (0)