From da8aa3f1e32c08b52eac16214a2abf4cfa9011f1 Mon Sep 17 00:00:00 2001 From: Ty Date: Fri, 15 Aug 2014 11:33:34 -0400 Subject: [PATCH] Fix issue where broken Jedis resources were not being properly handled. --- .../serverdata/RedisServerRepository.java | 100 ++++++++++++++++-- 1 file changed, 91 insertions(+), 9 deletions(-) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 7d8cfa140..1ae8cf16c 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -14,6 +14,7 @@ import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.Pipeline; import redis.clients.jedis.Response; import redis.clients.jedis.Transaction; +import redis.clients.jedis.exceptions.JedisConnectionException; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -73,9 +74,18 @@ public class RedisServerRepository implements ServerRepository servers.add(Utility.deserialize(serializedData, MinecraftServer.class)); } } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return servers; @@ -94,9 +104,18 @@ public class RedisServerRepository implements ServerRepository String serializedData = jedis.get(dataKey); server = Utility.deserialize(serializedData, MinecraftServer.class); } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return server; @@ -120,9 +139,18 @@ public class RedisServerRepository implements ServerRepository transaction.zadd(setKey, expiry, serverName); transaction.exec(); } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } } @@ -142,9 +170,18 @@ public class RedisServerRepository implements ServerRepository transaction.zrem(setKey, serverName); transaction.exec(); } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } } @@ -188,9 +225,18 @@ public class RedisServerRepository implements ServerRepository } } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } Map serverGroups = new HashMap(); @@ -233,9 +279,18 @@ public class RedisServerRepository implements ServerRepository servers.add(new ServerGroup(data, _region)); } } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return servers; @@ -259,9 +314,18 @@ public class RedisServerRepository implements ServerRepository transaction.exec(); } } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return 0; @@ -283,9 +347,18 @@ public class RedisServerRepository implements ServerRepository String max = "+inf"; names = jedis.zrangeByScore(key, min, max); } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return names; @@ -306,9 +379,18 @@ public class RedisServerRepository implements ServerRepository String max = System.currentTimeMillis() + ""; names = jedis.zrangeByScore(key, min, max); } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + _jedisPool.returnBrokenResource(jedis); + jedis = null; + } finally { - _jedisPool.returnResource(jedis); + if (jedis != null) + { + _jedisPool.returnResource(jedis); + } } return names;