From 662416cd7b2d0e45658ff666ac246a37ac4fcbb1 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 28 Jun 2018 12:43:35 -0400 Subject: [PATCH] Fix DynamoDbLock.tryLock() for the real timeout Since the contract of the `tryLock()` to wait as close to the provided timeout as possible, then we should not wait for the `leasePeriod` as minimum. Also we should sleep in between attempts not more then provided timeout --- .../integration/aws/lock/DynamoDbLockRegistry.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java b/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java index 667e8f7..5fd6db3 100644 --- a/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java +++ b/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java @@ -466,10 +466,12 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing return false; } - long timeToWaitForLock = System.currentTimeMillis() - start + TimeUnit.MILLISECONDS.convert(time, unit); + long refreshPeriod = System.currentTimeMillis() - start + TimeUnit.MILLISECONDS.convert(time, unit); + long timeToWaitForLock = refreshPeriod - DynamoDbLockRegistry.this.leaseDuration; + this.acquireLockOptionsBuilder .withAdditionalTimeToWaitForLock(timeToWaitForLock) - .withRefreshPeriod(timeToWaitForLock); + .withRefreshPeriod(refreshPeriod); boolean acquired = false; try {