Skip to content

Commit 1e1e1ac

Browse files
committed
Fix DynamoDbLockRegistry.tryLock for "fair" time
Since we don't have choice and wait at minimum `leaseDuration` to be able to iterate in the Amazon LockClient at least two times and that is going to be just a contract of this client, so we need to add up a `timeout` for the `tryLock` to that `leaseDuration`
1 parent dd52e8f commit 1e1e1ac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ public void lockInterruptibly() throws InterruptedException {
448448

449449
@Override
450450
public boolean tryLock() {
451-
awaitForActive();
452-
453451
try {
454452
return tryLock(0, TimeUnit.MILLISECONDS);
455453
}
@@ -461,14 +459,18 @@ public boolean tryLock() {
461459

462460
@Override
463461
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
462+
long start = System.currentTimeMillis();
463+
464464
awaitForActive();
465465

466466
if (!this.delegate.tryLock(time, unit)) {
467467
return false;
468468
}
469469

470+
long additionalTimeToWait = TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start;
471+
470472
this.acquireLockOptionsBuilder
471-
.withAdditionalTimeToWaitForLock(0L)
473+
.withAdditionalTimeToWaitForLock(additionalTimeToWait)
472474
.withRefreshPeriod(0L);
473475

474476
boolean acquired = false;

0 commit comments

Comments
 (0)