From 7a76265ac2a3bdcf3b443d3b72fec143304e7e8b Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Fri, 28 Jul 2023 07:11:00 +0300 Subject: [PATCH] Fixed - Setting RetryAttempts to 0, always throws an exception (regression since 3.23.1) #5203 --- .../connection/MasterSlaveConnectionManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java index b282e1cf0..487653442 100644 --- a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java @@ -183,24 +183,25 @@ public class MasterSlaveConnectionManager implements ConnectionManager { @Override public final void connect() throws InterruptedException { - for (int i = 0; i < config.getRetryAttempts(); i++) { + int attempts = config.getRetryAttempts() + 1; + for (int i = 0; i < attempts; i++) { try { - if (i == config.getRetryAttempts() - 1) { + if (i == attempts - 1) { lastAttempt = true; } doConnect(); return; } catch (Exception e) { + if (i == attempts - 1) { + lastAttempt = false; + throw e; + } try { Thread.sleep(config.getRetryInterval()); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); return; } - if (i == config.getRetryAttempts() - 1) { - lastAttempt = false; - throw e; - } } } } @@ -212,6 +213,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager { } else { masterSlaveEntry = new MasterSlaveEntry(this, serviceManager.getConnectionWatcher(), config); } + System.out.println(System.identityHashCode(this) + " master " + masterSlaveEntry); CompletableFuture masterFuture = masterSlaveEntry.setupMasterEntry(new RedisURI(config.getMasterAddress())); masterFuture.join();