Skip to content

RedisLock: Throw exception from unlock on expire #2661

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

Merged

Conversation

artembilan
Copy link
Member

The lock might be expired in target Redis store in between lock() and
unlock().
So, throw an IllegalStateException when lock is expired during
unlocking.
At the same time the lock lock is unlocked anyway.

Cherry-pick to 5.0.x

The lock might be expired in target Redis store in between `lock()` and
`unlock()`.
So, throw an `IllegalStateException` when lock is expired during
unlocking.
At the same time the lock lock is unlocked anyway.

**Cherry-pick to 5.0.x**
waitForExpire("foo");
lock1.unlock();
assertTrue(lock2.tryLock());
assertFalse(lock1.tryLock());
Copy link
Contributor

Choose a reason for hiding this comment

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

These two are redundant now - shouldn't the test for the new logic be in a different test?

@@ -301,6 +305,10 @@ public void unlock() {
return;
}
try {
if (!isAcquiredInThisProcess()) {
throw new IllegalStateException("Lock was released in the store due to expiration.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should be more explicit? ...due to expiration. The integrity of data protected by this lock may have been compromised. ?

* Add more info into the exception
@garyrussell garyrussell merged commit c5f29fc into spring-projects:master Dec 14, 2018
garyrussell pushed a commit that referenced this pull request Dec 14, 2018
* RedisLock: Throw exception from unlock on expire

The lock might be expired in target Redis store in between `lock()` and
`unlock()`.
So, throw an `IllegalStateException` when lock is expired during
unlocking.
At the same time the lock lock is unlocked anyway.

**Cherry-pick to 5.0.x**

* * Create a new test for exception
* Add more info into the exception
@garyrussell
Copy link
Contributor

Cherry-picked as 0199741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants