Skip to content

Commit f955473

Browse files
Improve: add the node ip and port for cluster exception
fixes #3466
1 parent c33bdf7 commit f955473

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private Socket connectToFirstSuccessfulHost(HostAndPort hostAndPort) throws Exce
6060
Collections.shuffle(hosts);
6161
}
6262

63-
JedisConnectionException jce = new JedisConnectionException("Failed to connect to any host resolved for DNS name.");
63+
JedisConnectionException jce = new JedisConnectionException("Failed to connect to host " + hostAndPort);
6464
for (InetAddress host : hosts) {
6565
try {
6666
Socket socket = new Socket();

src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public final <T> T executeCommand(CommandObject<T> commandObject) {
9696
} catch (JedisClusterOperationException jnrcne) {
9797
throw jnrcne;
9898
} catch (JedisConnectionException jce) {
99-
lastException = jce;
99+
lastException = new JedisConnectionException(
100+
"Cluster retry failed to " + (connection != null ? connection.toString() : ""), jce);
100101
++consecutiveConnectionFailures;
101102
log.debug("Failed connecting to Redis: {}", connection, jce);
102103
// "- 1" because we just did one, but the attemptsLeft counter hasn't been decremented yet
@@ -122,7 +123,9 @@ public final <T> T executeCommand(CommandObject<T> commandObject) {
122123
IOUtils.closeQuietly(connection);
123124
}
124125
if (Instant.now().isAfter(deadline)) {
125-
throw new JedisClusterOperationException("Cluster retry deadline exceeded.");
126+
throw new JedisClusterOperationException(
127+
"Cluster retry to " + (connection != null ? connection.toString() : "")
128+
+ " deadline exceeded.");
126129
}
127130
}
128131

src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public final <T> T executeCommand(CommandObject<T> commandObject) {
4848
return execute(connection, commandObject);
4949

5050
} catch (JedisConnectionException jce) {
51-
lastException = jce;
51+
lastException = new JedisConnectionException(
52+
"Retry failed to " + (connection != null ? connection.toString() : ""), jce);
5253
++consecutiveConnectionFailures;
5354
log.debug("Failed connecting to Redis: {}", connection, jce);
5455
// "- 1" because we just did one, but the attemptsLeft counter hasn't been decremented yet
@@ -62,7 +63,8 @@ public final <T> T executeCommand(CommandObject<T> commandObject) {
6263
}
6364
}
6465
if (Instant.now().isAfter(deadline)) {
65-
throw new JedisException("Retry deadline exceeded.");
66+
throw new JedisException("Retry to " + (connection != null ? connection.toString() : "")
67+
+ " deadline exceeded.");
6668
}
6769
}
6870

0 commit comments

Comments
 (0)