mirror of
				https://github.com/proxiodev/RedisBungee.git
				synced 2025-11-04 01:28:02 +00:00 
			
		
		
		
	Better handling of improperly-fetched Jedis resources.
This commit is contained in:
		
							parent
							
								
									cb61d90d6c
								
							
						
					
					
						commit
						e630116ff8
					
				@ -68,6 +68,7 @@ public class DataManager implements Listener {
 | 
				
			|||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            // Redis server has disappeared!
 | 
					            // Redis server has disappeared!
 | 
				
			||||||
            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					            if (tmpRsc != null)
 | 
				
			||||||
                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
					                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
				
			||||||
            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
					            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
@ -98,6 +99,7 @@ public class DataManager implements Listener {
 | 
				
			|||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            // Redis server has disappeared!
 | 
					            // Redis server has disappeared!
 | 
				
			||||||
            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					            if (tmpRsc != null)
 | 
				
			||||||
                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
					                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
				
			||||||
            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
					            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
@ -132,6 +134,7 @@ public class DataManager implements Listener {
 | 
				
			|||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            // Redis server has disappeared!
 | 
					            // Redis server has disappeared!
 | 
				
			||||||
            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					            if (tmpRsc != null)
 | 
				
			||||||
                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
					                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
				
			||||||
            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
					            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
				
			||||||
        } catch (UnknownHostException e) {
 | 
					        } catch (UnknownHostException e) {
 | 
				
			||||||
@ -191,6 +194,7 @@ public class DataManager implements Listener {
 | 
				
			|||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            // Redis server has disappeared!
 | 
					            // Redis server has disappeared!
 | 
				
			||||||
            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					            plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					            if (tmpRsc != null)
 | 
				
			||||||
                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
					                plugin.getPool().returnBrokenResource(tmpRsc);
 | 
				
			||||||
            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
					            throw new RuntimeException("Unable to get server for " + uuid, e);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
 | 
				
			|||||||
@ -106,6 +106,7 @@ public final class RedisBungee extends Plugin {
 | 
				
			|||||||
            return servers.build();
 | 
					            return servers.build();
 | 
				
			||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
 | 
					            getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
 | 
				
			||||||
 | 
					            if (jedis != null)
 | 
				
			||||||
                pool.returnBrokenResource(jedis);
 | 
					                pool.returnBrokenResource(jedis);
 | 
				
			||||||
            return Collections.singletonList(serverId);
 | 
					            return Collections.singletonList(serverId);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
@ -135,6 +136,7 @@ public final class RedisBungee extends Plugin {
 | 
				
			|||||||
            } catch (JedisConnectionException e) {
 | 
					            } catch (JedisConnectionException e) {
 | 
				
			||||||
                // Redis server has disappeared!
 | 
					                // Redis server has disappeared!
 | 
				
			||||||
                getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					                getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					                if (rsc != null)
 | 
				
			||||||
                    pool.returnBrokenResource(rsc);
 | 
					                    pool.returnBrokenResource(rsc);
 | 
				
			||||||
                throw new RuntimeException("Unable to get total player count", e);
 | 
					                throw new RuntimeException("Unable to get total player count", e);
 | 
				
			||||||
            } finally {
 | 
					            } finally {
 | 
				
			||||||
@ -181,6 +183,7 @@ public final class RedisBungee extends Plugin {
 | 
				
			|||||||
            } catch (JedisConnectionException e) {
 | 
					            } catch (JedisConnectionException e) {
 | 
				
			||||||
                // Redis server has disappeared!
 | 
					                // Redis server has disappeared!
 | 
				
			||||||
                getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					                getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					                if (rsc != null)
 | 
				
			||||||
                    pool.returnBrokenResource(rsc);
 | 
					                    pool.returnBrokenResource(rsc);
 | 
				
			||||||
                throw new RuntimeException("Unable to get all players online", e);
 | 
					                throw new RuntimeException("Unable to get all players online", e);
 | 
				
			||||||
            } finally {
 | 
					            } finally {
 | 
				
			||||||
@ -197,17 +200,7 @@ public final class RedisBungee extends Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
 | 
					    final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
 | 
				
			||||||
        checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
 | 
					        checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
 | 
				
			||||||
        Jedis jedis = pool.getResource();
 | 
					        sendChannelMessage("redisbungee-" + proxyId, command);
 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            jedis.publish("redisbungee-" + proxyId, command);
 | 
					 | 
				
			||||||
        } catch (JedisConnectionException e) {
 | 
					 | 
				
			||||||
            // Redis server has disappeared!
 | 
					 | 
				
			||||||
            getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					 | 
				
			||||||
            pool.returnBrokenResource(jedis);
 | 
					 | 
				
			||||||
            throw new RuntimeException("Unable to publish command", e);
 | 
					 | 
				
			||||||
        } finally {
 | 
					 | 
				
			||||||
            pool.returnResource(jedis);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final void sendChannelMessage(String channel, String message) {
 | 
					    final void sendChannelMessage(String channel, String message) {
 | 
				
			||||||
@ -217,6 +210,7 @@ public final class RedisBungee extends Plugin {
 | 
				
			|||||||
        } catch (JedisConnectionException e) {
 | 
					        } catch (JedisConnectionException e) {
 | 
				
			||||||
            // Redis server has disappeared!
 | 
					            // Redis server has disappeared!
 | 
				
			||||||
            getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
					            getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
 | 
				
			||||||
 | 
					            if (jedis != null)
 | 
				
			||||||
                pool.returnBrokenResource(jedis);
 | 
					                pool.returnBrokenResource(jedis);
 | 
				
			||||||
            throw new RuntimeException("Unable to publish channel message", e);
 | 
					            throw new RuntimeException("Unable to publish channel message", e);
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@ import lombok.NonNull;
 | 
				
			|||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import net.md_5.bungee.api.ProxyServer;
 | 
					import net.md_5.bungee.api.ProxyServer;
 | 
				
			||||||
import redis.clients.jedis.Jedis;
 | 
					import redis.clients.jedis.Jedis;
 | 
				
			||||||
 | 
					import redis.clients.jedis.exceptions.JedisConnectionException;
 | 
				
			||||||
import redis.clients.jedis.exceptions.JedisException;
 | 
					import redis.clients.jedis.exceptions.JedisException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Calendar;
 | 
					import java.util.Calendar;
 | 
				
			||||||
@ -78,7 +79,6 @@ public final class UUIDTranslator {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Let's try Redis.
 | 
					        // Let's try Redis.
 | 
				
			||||||
        Jedis jedis = plugin.getPool().getResource();
 | 
					        Jedis jedis = plugin.getPool().getResource();
 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            String stored = jedis.hget("uuid-cache", player.toLowerCase());
 | 
					            String stored = jedis.hget("uuid-cache", player.toLowerCase());
 | 
				
			||||||
            if (stored != null) {
 | 
					            if (stored != null) {
 | 
				
			||||||
@ -114,12 +114,11 @@ public final class UUIDTranslator {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        } catch (JedisException e) {
 | 
					        } catch (JedisException e) {
 | 
				
			||||||
            plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
 | 
					            plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
 | 
				
			||||||
 | 
					            if (jedis != null)
 | 
				
			||||||
 | 
					                plugin.getPool().returnBrokenResource(jedis);
 | 
				
			||||||
            // Go ahead and give them what we have.
 | 
					            // Go ahead and give them what we have.
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        } finally {
 | 
					 | 
				
			||||||
            plugin.getPool().returnResource(jedis);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return null; // Nope, game over!
 | 
					        return null; // Nope, game over!
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user