Skip to content

Commit ba6d35d

Browse files
authored
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`**
1 parent 0450a32 commit ba6d35d

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
@@ -476,13 +476,10 @@ public final void unlock() {
476476

477477
private void removeLockKey() {
478478
if (RedisLockRegistry.this.unlinkAvailable) {
479+
Boolean unlinkResult = null;
479480
try {
480-
boolean unlinkResult = removeLockKeyInnerUnlink();
481-
if (!unlinkResult) {
482-
throw new IllegalStateException("Lock was released in the store due to expiration. " +
483-
"The integrity of data protected by this lock may have been compromised.");
484-
}
485-
return;
481+
// Attempt to UNLINK the lock key; an exception indicates lack of UNLINK support
482+
unlinkResult = removeLockKeyInnerUnlink();
486483
}
487484
catch (Exception ex) {
488485
RedisLockRegistry.this.unlinkAvailable = false;
@@ -495,6 +492,15 @@ private void removeLockKey() {
495492
"falling back to the regular DELETE command: " + ex.getMessage());
496493
}
497494
}
495+
496+
if (Boolean.TRUE.equals(unlinkResult)) {
497+
// Lock key successfully unlinked
498+
return;
499+
}
500+
else if (Boolean.FALSE.equals(unlinkResult)) {
501+
throw new IllegalStateException("Lock was released in the store due to expiration. " +
502+
"The integrity of data protected by this lock may have been compromised.");
503+
}
498504
}
499505
if (!removeLockKeyInnerDelete()) {
500506
throw new IllegalStateException("Lock was released in the store due to expiration. " +

0 commit comments

Comments
 (0)