Skip to content

Commit 5dd01b7

Browse files
authored
GH-2504: Clear Deffered Channel Close Executor
Addendum to #2504 - when the connection is reset, the `channelsExecutor` is shut down. It needs to be reset so that a new one is created, if necessary. Also fix synchronization. **cherry-pick to 2.4.x**
1 parent b860606 commit 5dd01b7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,24 @@ public final void destroy() {
846846
resetConnection();
847847
if (getContextStopped()) {
848848
this.stopped = true;
849-
if (this.channelsExecutor != null) {
850-
try {
851-
if (!this.inFlightAsyncCloses.await(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
852-
this.logger.warn("Async closes are still in-flight: " + this.inFlightAsyncCloses.getCount());
849+
synchronized (this.connectionMonitor) {
850+
if (this.channelsExecutor != null) {
851+
try {
852+
if (!this.inFlightAsyncCloses.await(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
853+
this.logger
854+
.warn("Async closes are still in-flight: " + this.inFlightAsyncCloses.getCount());
855+
}
856+
this.channelsExecutor.shutdown();
857+
if (!this.channelsExecutor.awaitTermination(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
858+
this.logger.warn("Channel executor failed to shut down");
859+
}
853860
}
854-
this.channelsExecutor.shutdown();
855-
if (!this.channelsExecutor.awaitTermination(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
856-
this.logger.warn("Channel executor failed to shut down");
861+
catch (@SuppressWarnings(UNUSED) InterruptedException e) {
862+
Thread.currentThread().interrupt();
863+
}
864+
finally {
865+
this.channelsExecutor = null;
857866
}
858-
}
859-
catch (@SuppressWarnings(UNUSED) InterruptedException e) {
860-
Thread.currentThread().interrupt();
861867
}
862868
}
863869
}

0 commit comments

Comments
 (0)