Skip to content

Add lock renewal failure listener - #7254

Open
guikaua12 wants to merge 5 commits into
redisson:masterfrom
guikaua12:feat/4698-lock-renewal-failure-listener
Open

guikaua12 wants to merge 5 commits into
redisson:masterfrom
guikaua12:feat/4698-lock-renewal-failure-listener

Conversation

@guikaua12

Copy link
Copy Markdown

Problem

When a lock watchdog renewal fails, Redisson only logs the error. Applications have no way to react, for example, by stopping work that may continue after lock ownership is lost.

Fix

Adds LockRenewalFailureListener, configurable through Config#setLockRenewalFailureListener(...).

The listener receives the unmapped lock name, owner thread ID, and renewal failure cause. It is notified asynchronously for failed watchdog-renewal batches, including read-lock and fast multi-lock renewal paths, without delaying subsequent renewal scheduling.

Listener and name-mapping failures are isolated and logged so they do not stop renewal scheduling. A notification indicates that a renewal attempt failed; it does not itself mean the lock has expired or ownership has been lost.

Tests

Adds coverage verifying that the listener:

  • receives the expected lock name, thread ID, and failure cause;
  • is not called for successful renewals;
  • only receives locks from the failed renewal batch;
  • does not block subsequent scheduling when it is slow or throws; and
  • does not stop scheduling when name mapping fails.

Fixes #4698

Signed-off-by: Guilherme Kauã da Silva <[email protected]>
@guikaua12 guikaua12 changed the title feat: add lock renewal failure listener Add lock renewal failure listener Jul 20, 2026
@mrniko mrniko added the feature label Aug 3, 2026
* @author Guilherme Kauã da Silva
*/
@FunctionalInterface
public interface LockRenewalFailureListener {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add lock per lock object. Use thread name if possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, do you want to register the listener for each lock object with RLock#addListener(LockRenewalFailureListener)?

For onFailure(String threadName, Throwable cause), the lock will store the owner thread name when it acquires the lock. If another thread calls the method, such as an asynchronous API that uses an explicit threadId, the method will use the thread ID instead.

Do you want to remove the Config-level listener, or keep it as a global fallback?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, do you want to register the listener for each lock object with RLock#addListener(LockRenewalFailureListener)?

Yes.
Remove the Config-level listener

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guikaua12

Any update?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrniko Hi, i will update it today

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrniko Pushed the changes.

There is a behavior worth confirming tho: the callback repeats on every watchdog cycle while renewal keeps failing, rather than firing once. Listener exceptions are logged and don't stop scheduling, and notifications are dispatched on the shared executor so a slow listener doesn't delay the next renewal.

@guikaua12

Copy link
Copy Markdown
Author

@mrniko Should i resolve the conflicts or you will do it on your own?

@guikaua12

Copy link
Copy Markdown
Author

@mrniko

@mrniko mrniko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments above. Please review.


private ChunkExecution<Boolean> buildChunk(Iterator<String> iter, int chunkSize) {
Map<String, Long> name2lockName = new HashMap<>();
Map<String, List<Tuple<Long, String>>> name2owners = new HashMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is value a collection?


private ChunkExecution<List<String>> buildChunk(Iterator<String> iter, int chunkSize) {
Map<String, Long> name2threadId = new HashMap<>(chunkSize);
Map<String, List<Tuple<Long, String>>> name2owners = new HashMap<>(chunkSize);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is value a collection?

@mrniko mrniko added this to the 4.8.1 milestone Oct 9, 2026
@mrniko

mrniko commented Oct 16, 2026

Copy link
Copy Markdown
Member

@guikaua12

Any updates?

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.

Add a callback on lock renewal failure

2 participants