Skip to content

Commit 162ef4a

Browse files
committed
Attempt to fix race condition in the CachingConnectionFactory
There is a logic in the `CachingConnectionFactory.destroy()` where we wait for `inFlightAsyncCloses`. However, it looks like we first close the main connection with all its channels. Therefore, we may end up with a `ConcurrentModificationException` when we iterate channels list for clean up, but in-flight requests still wait for their confirms, therefore they may come back to the cache meanwhile we are trying to clean up
1 parent ced72ed commit 162ef4a

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,6 @@ private void refreshProxyConnection(ChannelCachingConnectionProxy connection) {
861861
*/
862862
@Override
863863
public final void destroy() {
864-
super.destroy();
865-
resetConnection();
866864
if (getContextStopped()) {
867865
this.stopped = true;
868866
this.connectionLock.lock();
@@ -890,6 +888,8 @@ public final void destroy() {
890888
this.connectionLock.unlock();
891889
}
892890
}
891+
super.destroy();
892+
resetConnection();
893893
}
894894

895895
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
* @since 1.1
9696
*
9797
*/
98-
@RabbitAvailable(queues = RabbitTemplatePublisherCallbacksIntegrationTests.ROUTE)
99-
public class RabbitTemplatePublisherCallbacksIntegrationTests {
98+
@RabbitAvailable(queues = RabbitTemplatePublisherCallbacksIntegration1Tests.ROUTE)
99+
public class RabbitTemplatePublisherCallbacksIntegration1Tests {
100100

101101
public static final String ROUTE = "test.queue.RabbitTemplatePublisherCallbacksIntegrationTests";
102102

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 the original author or authors.
2+
* Copyright 2016-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,9 +41,9 @@
4141
* @since 1.6
4242
*
4343
*/
44-
@RabbitAvailable(queues = { RabbitTemplatePublisherCallbacksIntegrationTests2.ROUTE,
45-
RabbitTemplatePublisherCallbacksIntegrationTests2.ROUTE2 })
46-
public class RabbitTemplatePublisherCallbacksIntegrationTests2 {
44+
@RabbitAvailable(queues = { RabbitTemplatePublisherCallbacksIntegration2Tests.ROUTE,
45+
RabbitTemplatePublisherCallbacksIntegration2Tests.ROUTE2 })
46+
public class RabbitTemplatePublisherCallbacksIntegration2Tests {
4747

4848
public static final String ROUTE = "test.queue.RabbitTemplatePublisherCallbacksIntegrationTests2";
4949

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2021 the original author or authors.
2+
* Copyright 2018-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,10 +41,10 @@
4141
* @since 2.1
4242
*
4343
*/
44-
@RabbitAvailable(queues = { RabbitTemplatePublisherCallbacksIntegrationTests3.QUEUE1,
45-
RabbitTemplatePublisherCallbacksIntegrationTests3.QUEUE2,
46-
RabbitTemplatePublisherCallbacksIntegrationTests3.QUEUE3 })
47-
public class RabbitTemplatePublisherCallbacksIntegrationTests3 {
44+
@RabbitAvailable(queues = { RabbitTemplatePublisherCallbacksIntegration3Tests.QUEUE1,
45+
RabbitTemplatePublisherCallbacksIntegration3Tests.QUEUE2,
46+
RabbitTemplatePublisherCallbacksIntegration3Tests.QUEUE3 })
47+
public class RabbitTemplatePublisherCallbacksIntegration3Tests {
4848

4949
public static final String QUEUE1 = "synthetic.nack";
5050

0 commit comments

Comments
 (0)