Skip to content

Commit 86656de

Browse files
EddieChoChoartembilan
authored andcommitted
GH-8699: Fix Issue of removeLockKey()
In the current code, an `IllegalStateException` might be thrown from the try block while invoking the `removeLockKeyInnerUnlink()` method, especially when caused by key expiration (resulting in `unlinkResult == false`). This triggers the check block, which incorrectly sets the `unlinkAvailable` flag to `false`, even if the Redis server supports the unlink operation. As a consequence, the subsequent `removeLockKeyInnerDelete()` method is invoked when it should not be. * `IllegalStateException` should not be thrown from try block * Add a comment and fix Checkstyle violations **Cherry-pick to `6.1.x` & `6.0.x`** (cherry picked from commit ba6d35d)
1 parent 156caa6 commit 86656de

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,10 @@ public final void unlock() {
465465

466466
private void removeLockKey() {
467467
if (RedisLockRegistry.this.unlinkAvailable) {
468+
Boolean unlinkResult = null;
468469
try {
469-
boolean unlinkResult = removeLockKeyInnerUnlink();
470-
if (!unlinkResult) {
471-
throw new IllegalStateException("Lock was released in the store due to expiration. " +
472-
"The integrity of data protected by this lock may have been compromised.");
473-
}
474-
return;
470+
// Attempt to UNLINK the lock key; an exception indicates lack of UNLINK support
471+
unlinkResult = removeLockKeyInnerUnlink();
475472
}
476473
catch (Exception ex) {
477474
RedisLockRegistry.this.unlinkAvailable = false;
@@ -484,6 +481,15 @@ private void removeLockKey() {
484481
"falling back to the regular DELETE command: " + ex.getMessage());
485482
}
486483
}
484+
485+
if (Boolean.TRUE.equals(unlinkResult)) {
486+
// Lock key successfully unlinked
487+
return;
488+
}
489+
else if (Boolean.FALSE.equals(unlinkResult)) {
490+
throw new IllegalStateException("Lock was released in the store due to expiration. " +
491+
"The integrity of data protected by this lock may have been compromised.");
492+
}
487493
}
488494
if (!removeLockKeyInnerDelete()) {
489495
throw new IllegalStateException("Lock was released in the store due to expiration. " +

0 commit comments

Comments
 (0)