Skip to content

Commit 562bc77

Browse files
committed
GH-2907: Use CF.closeTimeout for confirms wait
Fixes: #2907 Issue link: #2907 The current hard-coded `5 seconds` is not enough in real applications under heavy load * Fix `CachingConnectionFactory` to use `getCloseTimeout()` for `publisherCallbackChannel.waitForConfirms()` which is `30 seconds` by default, but can be modified via `CachingConnectionFactory.setCloseTimeout()` **Auto-cherry-pick to `3.1.x`**
1 parent d910a8b commit 562bc77

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,9 @@ protected ExecutorService getExecutorService() {
479479
}
480480

481481
/**
482-
* How long to wait (milliseconds) for a response to a connection close operation from the broker; default 30000 (30
483-
* seconds).
482+
* How long to wait (milliseconds) for a response to a connection close operation from the broker;
483+
* default 30000 (30 seconds).
484+
* Also used for {@link com.rabbitmq.client.Channel#waitForConfirms()}.
484485
* @param closeTimeout the closeTimeout to set.
485486
*/
486487
public void setCloseTimeout(int closeTimeout) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,6 @@ public String toString() {
10871087

10881088
private final class CachedChannelInvocationHandler implements InvocationHandler {
10891089

1090-
private static final int ASYNC_CLOSE_TIMEOUT = 5_000;
1091-
10921090
private final ChannelCachingConnectionProxy theConnection;
10931091

10941092
private final Deque<ChannelProxy> channelList;
@@ -1302,7 +1300,7 @@ private void returnToCache(ChannelProxy proxy) {
13021300
getChannelsExecutor()
13031301
.execute(() -> {
13041302
try {
1305-
publisherCallbackChannel.waitForConfirms(ASYNC_CLOSE_TIMEOUT);
1303+
publisherCallbackChannel.waitForConfirms(getCloseTimeout());
13061304
}
13071305
catch (InterruptedException ex) {
13081306
Thread.currentThread().interrupt();
@@ -1426,10 +1424,10 @@ private void asyncClose() {
14261424
executorService.execute(() -> {
14271425
try {
14281426
if (ConfirmType.CORRELATED.equals(CachingConnectionFactory.this.confirmType)) {
1429-
channel.waitForConfirmsOrDie(ASYNC_CLOSE_TIMEOUT);
1427+
channel.waitForConfirmsOrDie(getCloseTimeout());
14301428
}
14311429
else {
1432-
Thread.sleep(ASYNC_CLOSE_TIMEOUT);
1430+
Thread.sleep(5_000); // NOSONAR - some time to give the channel a chance to ack
14331431
}
14341432
}
14351433
catch (@SuppressWarnings(UNUSED) InterruptedException e1) {

0 commit comments

Comments
 (0)