Skip to content

Commit baa6597

Browse files
garyrussellartembilan
authored andcommitted
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** (cherry picked from commit 5dd01b7)
1 parent 82a7228 commit baa6597

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
@@ -860,18 +860,24 @@ public final void destroy() {
860860
resetConnection();
861861
if (getContextStopped()) {
862862
this.stopped = true;
863-
if (this.channelsExecutor != null) {
864-
try {
865-
if (!this.inFlightAsyncCloses.await(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
866-
this.logger.warn("Async closes are still in-flight: " + this.inFlightAsyncCloses.getCount());
863+
synchronized (this.connectionMonitor) {
864+
if (this.channelsExecutor != null) {
865+
try {
866+
if (!this.inFlightAsyncCloses.await(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
867+
this.logger
868+
.warn("Async closes are still in-flight: " + this.inFlightAsyncCloses.getCount());
869+
}
870+
this.channelsExecutor.shutdown();
871+
if (!this.channelsExecutor.awaitTermination(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
872+
this.logger.warn("Channel executor failed to shut down");
873+
}
867874
}
868-
this.channelsExecutor.shutdown();
869-
if (!this.channelsExecutor.awaitTermination(CHANNEL_EXEC_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
870-
this.logger.warn("Channel executor failed to shut down");
875+
catch (@SuppressWarnings(UNUSED) InterruptedException e) {
876+
Thread.currentThread().interrupt();
877+
}
878+
finally {
879+
this.channelsExecutor = null;
871880
}
872-
}
873-
catch (@SuppressWarnings(UNUSED) InterruptedException e) {
874-
Thread.currentThread().interrupt();
875881
}
876882
}
877883
}

0 commit comments

Comments
 (0)