From 4363d121a42f89066cf163c1182aead3ae11de84 Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 3 Dec 2020 13:07:27 +0200 Subject: [PATCH] Finally fixed connection leak in /reloadredis !!! --- .../rediskript/commands/CommandReloadRedis.java | 2 +- .../rediskript/managers/RedisManager.java | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/limework/rediskript/commands/CommandReloadRedis.java b/src/main/java/net/limework/rediskript/commands/CommandReloadRedis.java index a67d0ba..3fcf3e6 100644 --- a/src/main/java/net/limework/rediskript/commands/CommandReloadRedis.java +++ b/src/main/java/net/limework/rediskript/commands/CommandReloadRedis.java @@ -22,7 +22,7 @@ public class CommandReloadRedis implements CommandExecutor { } plugin.getRedisManager().reload(); //not sending to sender, because this command can only be executed via console - Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded via command! Note this command is not stable, it should only be used in urgent cases where you absolutely need to change config details without restarting the server.")); + Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!")); return false; } diff --git a/src/main/java/net/limework/rediskript/managers/RedisManager.java b/src/main/java/net/limework/rediskript/managers/RedisManager.java index 029b49d..e34d57d 100644 --- a/src/main/java/net/limework/rediskript/managers/RedisManager.java +++ b/src/main/java/net/limework/rediskript/managers/RedisManager.java @@ -62,8 +62,8 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable { RedisService = Executors.newSingleThreadExecutor(); try { this.subscribeJedis = this.jedisPool.getResource(); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} + this.channels = config.getStringList("Channels"); encryption = new Encryption(config); @@ -80,8 +80,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable { plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&cConnecting to redis...")); if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource(); plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&aRedis connected!")); - int byteArr2dSize = 1; - byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize]; + byte[][] channelsInByte = new byte[channels.size()][1]; for (int x = 0; x < channels.size(); x++) { channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8); } @@ -241,14 +240,17 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable { if (this.subscribeJedis != null) { this.unsubscribe(); this.subscribeJedis.close(); - this.subscribeJedis.getClient().close(); - this.jedisPool.getResource().close(); } - isShuttingDown.set(true); + + if (this.jedisPool != null) { + jedisPool.close(); + jedisPool = null; + } this.RedisReconnector.shutdown(); this.RedisService.shutdown(); this.RedisService = null; this.RedisReconnector = null; + encryption = null; } public void reload() {