Skip to content

Commit d20796a

Browse files
committed
spring-projectsGH-8699: Atomic Redis script for unlock()
IllegalStateException should not be thrown from try block
1 parent 0450a32 commit d20796a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,9 @@ 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+
unlinkResult = removeLockKeyInnerUnlink();
486482
}
487483
catch (Exception ex) {
488484
RedisLockRegistry.this.unlinkAvailable = false;
@@ -495,6 +491,14 @@ private void removeLockKey() {
495491
"falling back to the regular DELETE command: " + ex.getMessage());
496492
}
497493
}
494+
495+
if(Boolean.TRUE.equals(unlinkResult)) {
496+
return;
497+
}
498+
else if (Boolean.FALSE.equals(unlinkResult)) {
499+
throw new IllegalStateException("Lock was released in the store due to expiration. " +
500+
"The integrity of data protected by this lock may have been compromised.");
501+
}
498502
}
499503
if (!removeLockKeyInnerDelete()) {
500504
throw new IllegalStateException("Lock was released in the store due to expiration. " +

0 commit comments

Comments
 (0)