Fix "TryLock interrupted keeps renewing lock indefinitely"

Signed-off-by: NCésar Luis Alvargonzález <cesar.alvargonzalez@revolut.com>
上级 28033956
......@@ -174,7 +174,13 @@ public abstract class RedissonBaseLock extends RedissonExpirable implements RLoc
oldEntry.addThreadId(threadId);
} else {
entry.addThreadId(threadId);
renewExpiration();
try {
renewExpiration();
} finally {
if (Thread.currentThread().isInterrupted()) {
cancelExpirationRenewal(threadId);
}
}
}
}
......
......@@ -112,6 +112,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
try {
future.await();
} catch (InterruptedException e) {
future.cancel(true);
Thread.currentThread().interrupt();
throw new RedisException(e);
}
......
......@@ -111,6 +111,29 @@ public class RedissonLockTest extends BaseConcurrentTest {
runner.stop();
}
@Test
public void testLockIsNotRenewedAfterInterruptedTryLock() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
RLock lock = redisson.getLock("myLock");
assertThat(lock.isLocked()).isFalse();
Thread thread = new Thread(() -> {
countDownLatch.countDown();
if (!lock.tryLock()) {
return;
}
lock.unlock();
});
thread.start();
countDownLatch.await();
// let the tcp request be sent out
TimeUnit.MILLISECONDS.sleep(5);
thread.interrupt();
TimeUnit.SECONDS.sleep(45);
assertThat(lock.isLocked()).isFalse();
}
@Test
public void testRedisFailed() {
Assertions.assertThrows(WriteRedisConnectionException.class, () -> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册