Properly close jedis connection in case of exceptions
This commit is contained in:
@@ -126,20 +126,24 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
|||||||
|
|
||||||
log.fine("Connecting to Sentinel " + hap);
|
log.fine("Connecting to Sentinel " + hap);
|
||||||
|
|
||||||
|
Jedis jedis = null;
|
||||||
try {
|
try {
|
||||||
Jedis jedis = new Jedis(hap.getHost(), hap.getPort());
|
jedis = new Jedis(hap.getHost(), hap.getPort());
|
||||||
|
|
||||||
if (master == null) {
|
if (master == null) {
|
||||||
master = toHostAndPort(jedis
|
master = toHostAndPort(jedis
|
||||||
.sentinelGetMasterAddrByName(masterName));
|
.sentinelGetMasterAddrByName(masterName));
|
||||||
log.fine("Found Redis master at " + master);
|
log.fine("Found Redis master at " + master);
|
||||||
jedis.disconnect();
|
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
log.warning("Cannot connect to sentinel running @ " + hap
|
log.warning("Cannot connect to sentinel running @ " + hap
|
||||||
+ ". Trying next one.");
|
+ ". Trying next one.");
|
||||||
}
|
} finally {
|
||||||
|
if (jedis != null) {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user