-
Notifications
You must be signed in to change notification settings - Fork 1.1k
RedisLockRegistry expireAfter doesn't work #3401
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
Also, I find that if the unlock method is not called, the lock cannot be obtained again. This seems to have been affected by ReentrantLock |
Would be great to have some code to play with. There is no Thanks for understanding. |
But most of the time, we need to be able to release locks automatically after the lock holder has held them for a certain amount of time, which is one of the reasons for using Redis. Maybe we can choose whether or not we need |
Well, that's not how locks are designed and you definitely can't release the lock if you are not a holder of it. We have a feature request like this: https://jira.spring.io/browse/INT-4286, so probably we can have some compromise eventually. But still: I'm against unlocking outside from the lock owner... See also this discussion: #2894 |
Ok, thank you for your answer |
In what version(s) of Spring Integration are you seeing this issue?
For example:
5.3.1.RELEASE
Describe the bug
I create a RedisLockRegistry and set expireAfter to 1000L .
After obtain the Lock object, invoke tryLock (3000, TimeUnit.MILLISECONDS) method.
Print 'lock-test' to sleep 2000L milliseconds, then call unlock.
When two threads come in at the same time, the second thread should get the lock one second after the first thread,
However, what observe now is that the two threads are always two seconds apart, seemingly unaffected by the expireAfter field.
thanks
To Reproduce
2020-10-10 15:40:46,063 [boundedElastic-2] INFO c.e.s.raffle.utils.RedisLockUtils.lambda$null$1(RedisLockUtils.java:65) - try obtain lock
2020-10-10 15:40:46,066 [boundedElastic-2] INFO c.e.s.raffle.utils.RedisLockUtils.lambda$null$1(RedisLockUtils.java:68) - Got the distributed lock and executing , key = test , time = 2020-10-10T15:40:46.066
lock-test
2020-10-10 15:40:47,006 [boundedElastic-1] INFO c.e.s.raffle.utils.RedisLockUtils.lambda$null$1(RedisLockUtils.java:65) - try obtain lock
2020-10-10 15:40:48,069 [boundedElastic-1] INFO c.e.s.raffle.utils.RedisLockUtils.lambda$null$1(RedisLockUtils.java:68) - Got the distributed lock and executing , key = test , time = 2020-10-10T15:40:48.069
lock-test
The text was updated successfully, but these errors were encountered: