diff --git a/src/main/java/org/redisson/CommandExecutorService.java b/src/main/java/org/redisson/CommandExecutorService.java index c55405208..7a728b4cf 100644 --- a/src/main/java/org/redisson/CommandExecutorService.java +++ b/src/main/java/org/redisson/CommandExecutorService.java @@ -429,7 +429,7 @@ public class CommandExecutorService implements CommandExecutor { return; } if (attempt == connectionManager.getConfig().getRetryAttempts()) { - attemptPromise.setFailure(ex.get()); + attemptPromise.tryFailure(ex.get()); return; } if (!attemptPromise.cancel(false)) { diff --git a/src/main/java/org/redisson/connection/ConnectionEntry.java b/src/main/java/org/redisson/connection/ConnectionEntry.java index 71c877ad0..f7acd33f4 100644 --- a/src/main/java/org/redisson/connection/ConnectionEntry.java +++ b/src/main/java/org/redisson/connection/ConnectionEntry.java @@ -64,6 +64,10 @@ public class ConnectionEntry { failedAttempts.set(0); } + public int getFailedAttempts() { + return failedAttempts.get(); + } + public int incFailedAttempts() { return failedAttempts.incrementAndGet(); } diff --git a/src/main/java/org/redisson/misc/ConnectionPool.java b/src/main/java/org/redisson/misc/ConnectionPool.java index aacad5850..3003e68c1 100644 --- a/src/main/java/org/redisson/misc/ConnectionPool.java +++ b/src/main/java/org/redisson/misc/ConnectionPool.java @@ -102,7 +102,7 @@ public class ConnectionPool { } protected boolean tryAcquireConnection(SubscribesConnectionEntry entry) { - return entry.tryAcquireConnection(); + return entry.getFailedAttempts() < config.getSlaveFailedAttempts() && entry.tryAcquireConnection(); } protected T poll(SubscribesConnectionEntry entry) { @@ -168,8 +168,8 @@ public class ConnectionPool { private void promiseFailure(SubscribesConnectionEntry entry, Promise promise, T conn) { + int attempts = entry.incFailedAttempts(); if (entry.getNodeType() == NodeType.SLAVE) { - int attempts = entry.incFailedAttempts(); if (attempts == config.getSlaveFailedAttempts()) { connectionManager.slaveDown(masterSlaveEntry, entry.getClient().getAddr().getHostName(), entry.getClient().getAddr().getPort(), FreezeReason.RECONNECT);