Skip to content

Commit

Permalink
Carry first suppressed exception within JedisNoReachableClusterNodeEx…
Browse files Browse the repository at this point in the history
…ception (#2233)
  • Loading branch information
sazzad16 authored Dec 8, 2020
1 parent 1e1ce47 commit 3418710
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Jedis getConnection() {

List<JedisPool> pools = cache.getShuffledNodesPool();

JedisException suppressed = null;
for (JedisPool pool : pools) {
Jedis jedis = null;
try {
Expand All @@ -82,19 +83,26 @@ public Jedis getConnection() {
continue;
}

String result = jedis.ping();

if (result.equalsIgnoreCase("pong")) return jedis;
if (jedis.ping().equalsIgnoreCase("pong")) {
return jedis;
}

jedis.close();
} catch (JedisException ex) {
if (suppressed == null) { // remembering first suppressed exception
suppressed = ex;
}
if (jedis != null) {
jedis.close();
}
}
}

throw new JedisNoReachableClusterNodeException("No reachable node in cluster");
JedisNoReachableClusterNodeException noReachableNode = new JedisNoReachableClusterNodeException("No reachable node in cluster");
if (suppressed != null) {
noReachableNode.addSuppressed(suppressed);
}
throw noReachableNode;
}

@Override
Expand Down

0 comments on commit 3418710

Please sign in to comment.