Skip to content

Fixed - lock watchdog renewal timeouts accumulate after the renewal task restarts - #7459

Merged
mrniko merged 1 commit into
redisson:masterfrom
oversk7:fix/renewal-task-single-timeout
Dec 1, 2026
Merged

mrniko merged 1 commit into
redisson:masterfrom
oversk7:fix/renewal-task-single-timeout

Conversation

@oversk7

@oversk7 oversk7 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #7454.

Problem
RenewalTask.stop() only clears running and leaves the already armed timeout in the timer. When a lock is added again, add() → tryRun() → schedule() arms a second timeout. When the old one fires it sees running == true and keeps rescheduling itself. Each time the set of renewed locks goes from empty to non-empty, one more periodic task is added. A worker that takes one lock at a time ends up sending a fast-growing stream of renewal scripts.

Fix
As suggested in #7454 by garvit-joshi (thanks for the analysis): a scheduled flag allows at most one pending timeout. run() clears it, and schedule() arms a new timeout only if it wins the CAS. A lock added while a timeout is pending gets its first renewal when that timeout fires, within lockWatchdogTimeout / 3, the same as a lock added while the task is already running.

Test
Added RedissonLockExpirationRenewalTest#testRenewalTimeoutsDontAccumulate: 20 lock/unlock cycles, then a 3 s hold with lockWatchdogTimeout 1000 ms, counting EVAL/EVALSHA calls during the hold.

  • master: 171 script calls, fails
  • with the fix: passes (bound is 12; one periodic task renews about 9 times)

Also checked (Windows 11, Docker, Redis 7, JDK 25)

  • The reproducer from Lock watchdog: renewal tasks multiply each time the set of renewed locks goes empty and non-empty again #7454 (lockWatchdogTimeout 3000 ms, 20 s): 1,457 renewal scripts on master, 12 with the fix
  • Single 20 s hold: 19 renewals, the lock doesn't expire
  • RedissonLockExpirationRenewalTest, RedissonLockTest, RedissonReadWriteLockTest, RedissonFairLockTest, RedissonMultiLockTest, RedissonFasterMultiLockTest, renewal.*Test: all pass except the *InCluster tests (cluster containers don't start on my Docker for Windows) and RedissonFairLockTest#testConcurrency_MultiInstance_Ordering. testConcurrency_MultiInstance_Ordering and RedissonLockTest#testInCluster fail the same way on unpatched master; the other cluster tests fail with the same container-startup error.
  • checkstyle:check passes

…ask restarts redisson#7454

stop() only cleared the running flag and left the already armed timeout
in the timer, so each restart of the renewal task added one more periodic
timeout. Allow at most one pending timeout.

Signed-off-by: OverSky <[email protected]>
@mrniko mrniko added this to the 4.9.0 milestone Dec 1, 2026
@mrniko mrniko added the bug label Dec 1, 2026
@mrniko
mrniko merged commit 2180c63 into redisson:master Dec 1, 2026
4 checks passed
@mrniko

mrniko commented Dec 1, 2026

Copy link
Copy Markdown
Member

Thanks for contribution

@mrniko

mrniko commented Dec 1, 2026

Copy link
Copy Markdown
Member

@oversk7

I did a refactoring 1d8129a

Please review

@oversk7

oversk7 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the refactoring, LGTM. Arming the timeout after compute() returns closes the window I missed, and keeping only the scheduled flag is much simpler. I ran RedissonLockExpirationRenewalTest on 1d8129a locally and all 6 tests pass, including the new read-lock case.

@mrniko

mrniko commented Dec 1, 2026

Copy link
Copy Markdown
Member

@oversk7

Good. Thank you

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: renewal tasks multiply each time the set of renewed locks goes empty and non-empty again

2 participants