Skip to content

Commit 1af31ba

Browse files
authored
Wait for Redis server to be stable after SCRIPT KILL (#2657)
* Wait for Redis server to be stable after SCRIPT KILL * Checking SCRIPT KILL status Hinted by Redis developers
1 parent c41d838 commit 1af31ba

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/test/java/redis/clients/jedis/tests/PipeliningTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import redis.clients.jedis.Response;
3131
import redis.clients.jedis.Tuple;
3232
import redis.clients.jedis.exceptions.AbortedTransactionException;
33+
import redis.clients.jedis.exceptions.JedisBusyException;
3334
import redis.clients.jedis.exceptions.JedisDataException;
3435
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
3536
import redis.clients.jedis.util.SafeEncoder;
@@ -734,13 +735,41 @@ public void execAbort() {
734735
assertSame(AbortedTransactionException.class, ex.getClass());
735736
} finally {
736737
try {
737-
jedis.scriptKill();
738+
String status = jedis.scriptKill();
739+
// https://github.com/redis/jedis/issues/2656
740+
if ("OK".equalsIgnoreCase(status)) {
741+
scriptKillWait();
742+
} else {
743+
// #2656: Checking if this status is actually 'OK' when error occurs in next command.
744+
org.apache.logging.log4j.LogManager.getLogger().error(
745+
String.format("Status if SCRIPT KILL command is \"%s\"", status));
746+
}
738747
} finally {
739748
jedis.configSet(luaTimeLimitKey, luaTimeLimit);
740749
}
741750
}
742751
}
743752

753+
private void scriptKillWait() {
754+
int attemptLeft = 10;
755+
while (attemptLeft > 0) {
756+
try (Jedis pingJedis = createJedis()) {
757+
while (attemptLeft > 0) {
758+
try {
759+
pingJedis.ping();
760+
return; // wait is over
761+
} catch (JedisBusyException busy) {
762+
--attemptLeft;
763+
Thread.sleep(10); // BUSY, waiting for some time
764+
}
765+
}
766+
} catch (Exception any) {
767+
--attemptLeft;
768+
// try new connection
769+
}
770+
}
771+
}
772+
744773
private void verifyHasBothValues(String firstKey, String secondKey, String value1, String value2) {
745774
assertFalse(firstKey.equals(secondKey));
746775
assertTrue(firstKey.equals(value1) || firstKey.equals(value2));

0 commit comments

Comments
 (0)