Skip to content

Commit

Permalink
Fix RedisClient not getting closed on connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmq committed Jun 1, 2024
1 parent bd3346e commit b4a77c3
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dev.magicmq.pyspigot.manager.script.Script;
import dev.magicmq.pyspigot.util.ScriptUtils;
import io.lettuce.core.ClientOptions;
import io.lettuce.core.RedisConnectionException;
import io.lettuce.core.RedisURI;

import java.util.ArrayList;
Expand Down Expand Up @@ -135,11 +136,14 @@ public ScriptRedisClient openRedisClient(ClientType clientType, RedisURI redisUR
else /*if (clientType == ClientType.PUB_SUB)*/
client = new RedisPubSubClient(script, redisURI, clientOptions);

if (client.open()) {
try {
client.open();
addClient(client);
return client;
} else
throw new RuntimeException("Failed to open a connection to the redis server.");
} catch (RedisConnectionException e) {
client.close();
throw e;
}
}

/**
Expand Down

0 comments on commit b4a77c3

Please sign in to comment.