Skip to content

Commit d1f18b1

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 2e62707 commit d1f18b1

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,10 @@ public final void unlock() {
464464

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

0 commit comments

Comments
 (0)