Search code examples
javaredisredisson

Is there some kind of lock / semaphore with idle TTL


I have the following case.

In order to prevent concurrency resource access we are using RPermitExpirableSemaphore as a lock. From Expirable I would expect that "lock key" in Redis would be deleted after some TTL. But unfortunately it isn't.

For example:

  • A tries to acquire lock X
  • A creates (previously non existing) lock X with TTL 1m
  • A acquires lock X
  • B tries to acquire lock X
  • B awaits A to release lock X
  • B acquires lock X
  • 1 minute passed
  • Redis deletes lock (key) X

And if there will be new attempts to acquire lock X, scenario above will start from scratch.

Is there some kind of Lock / Semaphore in Redisson that provides this behaviour?

P.S. I can't delete semaphores manually because if there are other clients waiting for lock to be released they are ending up with exception that Semaphore does not exist (of course, because it was deleted by another client). And as a result we are having leaking keys (that's won't be used in future because accessed resource is temporal).


Solution

  • The issue has been fixed in version 3.12.0.
    Issue: https://github.com/redisson/redisson/issues/2444.
    Commit: https://github.com/redisson/redisson/commit/1954b8e6fbc262c0a75509ec75df98af73202fd4