Repository navigation
Fixed - lock watchdog renews a lock forever after an interrupted tryLock() #7463 - #7464
Merged
mrniko merged 1 commit intoDec 2, 2026
Merged
Conversation
…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]>
This was referenced Dec 1, 2026
Member
|
Thanks for contribution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()ofRedissonLockandRedissonSpinLockschedules 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()andtryLock(waitTime, ...)gets the same throughtryAcquire.The asynchronous methods are not changed. Their callers receive the result themselves, so they schedule the renewal as before.
RedissonReadLock,RedissonWriteLockandRedissonFairLockextendRedissonLockand use the same code.RedissonFasterMultiLockis built in the same way asRedissonLock. I have not tested or changed it.Tests
InterruptedAcquireTestis 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:
testInterruptedTryLockDoesNotRenewTheLocktestInterruptedSpinLockTryLockDoesNotRenewTheLocktestInterruptedLockDoesNotRenewTheLockThe 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#testLockIsNotRenewedAfterInterruptedTryLockpasses 5 of 5 runs with the change. Without the change it failed 5 of 5 runs when it was run alone.Verified locally:
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.
RedissonLockExpirationRenewalTestpassed too (6 of 6).