|
30 | 30 | import redis.clients.jedis.Response; |
31 | 31 | import redis.clients.jedis.Tuple; |
32 | 32 | import redis.clients.jedis.exceptions.AbortedTransactionException; |
| 33 | +import redis.clients.jedis.exceptions.JedisBusyException; |
33 | 34 | import redis.clients.jedis.exceptions.JedisDataException; |
34 | 35 | import redis.clients.jedis.tests.commands.JedisCommandTestBase; |
35 | 36 | import redis.clients.jedis.util.SafeEncoder; |
@@ -734,13 +735,41 @@ public void execAbort() { |
734 | 735 | assertSame(AbortedTransactionException.class, ex.getClass()); |
735 | 736 | } finally { |
736 | 737 | 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 | + } |
738 | 747 | } finally { |
739 | 748 | jedis.configSet(luaTimeLimitKey, luaTimeLimit); |
740 | 749 | } |
741 | 750 | } |
742 | 751 | } |
743 | 752 |
|
| 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 | + |
744 | 773 | private void verifyHasBothValues(String firstKey, String secondKey, String value1, String value2) { |
745 | 774 | assertFalse(firstKey.equals(secondKey)); |
746 | 775 | assertTrue(firstKey.equals(value1) || firstKey.equals(value2)); |
|
0 commit comments