Skip to content

Fixed - lock watchdog renews a lock forever after an interrupted tryLock() #7463 - #7464

Merged
mrniko merged 1 commit into
redisson:masterfrom
eatmoreduck:fix/interrupted-trylock-renewal
Dec 2, 2026
Merged

mrniko merged 1 commit into
redisson:masterfrom
eatmoreduck:fix/interrupted-trylock-renewal

Conversation

@eatmoreduck

@eatmoreduck eatmoreduck commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7463

Problem

A thread that is interrupted while tryLock() waits for the reply gets an exception and does not get the lock. When the reply arrives after that, the watchdog renewal is still scheduled for it, and the lock is renewed forever.

Fix

tryLock() of RedissonLock and RedissonSpinLock schedules the renewal after it has received the result, and not any more when the reply arrives. The attempt itself does not schedule it for these callers.

The first attempt of lock(), lockInterruptibly() and tryLock(waitTime, ...) gets the same through tryAcquire.

The asynchronous methods are not changed. Their callers receive the result themselves, so they schedule the renewal as before.

RedissonReadLock, RedissonWriteLock and RedissonFairLock extend RedissonLock and use the same code.

RedissonFasterMultiLock is built in the same way as RedissonLock. I have not tested or changed it.

Tests

InterruptedAcquireTest is new. It needs no Redis. The acquisition script does not run, and its reply is held back until the thread was interrupted.

These three fail without the change. In all of them Redis acquires the lock after the thread was interrupted, and the watchdog must not renew it:

  • testInterruptedTryLockDoesNotRenewTheLock
  • testInterruptedSpinLockTryLockDoesNotRenewTheLock
  • testInterruptedLockDoesNotRenewTheLock

The other seven pass with and without the change. They check that the renewal is still scheduled where it should be, also by the asynchronous tryLockAsync().

RedissonLockTest#testLockIsNotRenewedAfterInterruptedTryLock passes 5 of 5 runs with the change. Without the change it failed 5 of 5 runs when it was run alone.

Verified locally:

mvn -T 1C -B clean verify -DskipTests -Dmaven.test.skip=false -pl redisson
-> BUILD SUCCESS, 0 Checkstyle violations

mvn -B -pl redisson test -Dmaven.test.skip=false -Dtest=InterruptedAcquireTest -Dsurefire.failIfNoSpecifiedTests=false
-> Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
mvn -B -pl redisson test -Dmaven.test.skip=false -Dtest=RedissonFairLockTest -Dsurefire.failIfNoSpecifiedTests=false
-> Tests run: 38, Failures: 0, Errors: 0

mvn -B -pl redisson test -Dmaven.test.skip=false -Dtest=RedissonSpinLockTest -Dsurefire.failIfNoSpecifiedTests=false
-> Tests run: 23, Failures: 0, Errors: 1. The error is testInCluster, which cannot start the alpine/socat container on my machine.

mvn -B -pl redisson test -Dmaven.test.skip=false -Dtest='RedissonReadWriteLockTest#testReadLockExpirationRenewal+testLockUnlock+testWriteReadReentrancy+testIsLocked+testIsLockedOtherThread+testIsHeldByCurrentThreadOtherThread,RedissonLockTest#testConcurrency_MultiInstance+testConcurrencyLoop_MultiInstance+testLockUninterruptibly+testIsLockedOtherThread+testLockIsNotRenewedAfterInterruptedTryLock' -Dsurefire.failIfNoSpecifiedTests=false
-> Tests run: 11, Failures: 0, Errors: 0

mvn -B -pl redisson test -Dmaven.test.skip=false -Dtest='RedissonLockTest,RedissonReadWriteLockTest' -Dsurefire.failIfNoSpecifiedTests=false
-> Tests run: 59, Failures: 0, Errors: 3. The errors are the tests that set up a Redis cluster, which cannot start the alpine/socat container on my machine.

RedissonLockExpirationRenewalTest passed too (6 of 6).

…ock() redisson#7463

A thread that is interrupted while tryLock() waits for the reply gets an
exception and does not get the lock. When the reply arrives after that,
the watchdog renewal was still scheduled for it.

tryLock() of RedissonLock and RedissonSpinLock, and the first attempt of
lock(), lockInterruptibly() and tryLock(waitTime, ...) through tryAcquire,
now schedule the renewal after they have received the result. The attempt
itself does not schedule it for these callers. The asynchronous methods
are not changed.

Signed-off-by: yu.xia <[email protected]>
@mrniko mrniko added this to the 4.9.0 milestone Dec 2, 2026
@mrniko mrniko added the bug label Dec 2, 2026
@mrniko
mrniko merged commit ea71dbc into redisson:master Dec 2, 2026
4 checks passed
@mrniko

mrniko commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks for contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Lock watchdog renews a lock forever when tryLock() is interrupted before the reply arrives

2 participants