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
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user