-
Notifications
You must be signed in to change notification settings - Fork 1.2k
DefaultRedisCacheWriter potentially leaks lock in rare case? #2598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We merged just yesterday support for Lock TTL via #2597. Care to check out the snapshots to see whether the change helps in your case? |
Lock TTL is a good idea. |
As we provide a framework functionality, we cannot make assumptions over an ideal time to live. It's a concern of your application configuration to set an appropriate time to live. |
Hi Mark, the way I can figure out for an application developer to specify a lock ttl is to pass a lockTtlFunction in the variant with four parameters of RedisCacheWriter.lockingRedisCacheWriter, as well as passing the sleepTime and batchStrategy. |
We're using @Cacheable to annotate methods, and using Redis as the storage.
One day I found one of the @Cacheable method always blocked until timeout.
When I checked the corresponding redis keys, I found there was only one key with "~lock" suffix.
For example, configure the annotation like this:
In normal, there should be KEYS like this:
UserCache_spring|framework|usercache
. However, when this issue occurred, all such keys has expired (ttl=24 hours).There was only one key named
UserCache~lock
, it should have been there for more than 24 hours.The possible reason is, inside https://github.com/spring-projects/spring-data-redis/blob/main/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java#putIfAbsent, in a very rare condition, a writing thread crashes between the line the lock is created and the line entering try block, then it doesn't get guarantee to be released, so cause a lock leak problem.
A link of this issue in gitter: https://matrix.to/#/!MJtHKfEduxwvhntKyg:gitter.im/$BJCPcSX_PqDSf2wQpcz_LYNl4ixJCTNkkk2V6Un3kRg?via=gitter.im&via=matrix.org
The text was updated successfully, but these errors were encountered: