Skip to content

Commit ed89f12

Browse files
karllessardartembilan
authored andcommitted
GH-97: wait at least leaseDuration to acquire the lock
Fixes #97 This fixes an issue where `additionalTimeToWait` has a negative value that is subtracted later by the Amazon DynamoDB client to `leaseDuration`, making it impossible to acquire the lock if expired. Also allow to use the existing `refreshPeriod` properties in this case. * Use default refresh period in tryLock() The 'refreshPeriod' value might not satisfy both tryLock() and lock() requirements and should probably be used exclusively in the second case. We can make the value used for tryLock() configurable as well in another pull request. * Rollback previous commit and add author name
1 parent 857d184 commit ed89f12

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* Can create table in DynamoDB if an external {@link AmazonDynamoDBLockClient} is not provided.
6161
*
6262
* @author Artem Bilan
63+
* @author Karl Lessard
6364
*
6465
* @since 2.0
6566
*/
@@ -467,11 +468,11 @@ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
467468
return false;
468469
}
469470

470-
long additionalTimeToWait = TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start;
471+
long additionalTimeToWait = Math.max(TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start, 0L);
471472

472473
this.acquireLockOptionsBuilder
473474
.withAdditionalTimeToWaitForLock(additionalTimeToWait)
474-
.withRefreshPeriod(0L);
475+
.withRefreshPeriod(DynamoDbLockRegistry.this.refreshPeriod);
475476

476477
boolean acquired = false;
477478
try {

0 commit comments

Comments
 (0)