-
Notifications
You must be signed in to change notification settings - Fork 168
Description
In what version(s) of Spring Integration AWS are you seeing this issue?
>= 2.5.2
Describe the bug
DynamoDbLock.tryLock()
has no chance to acquire an abandoned lock no matter how many times you will try. It worked before #205 but with this fix abandoned locks can't re-acquired using DynamoDbLock.tryLock()
To Reproduce
- create a DynamoDB lock table with a lock (in AWS or in local stack)
- create a DynamoDbLockRegistry with the params that match the table/lock you created previously and try to lock it using 'tryLock()'
@Bean
public DynamoDbLockRegistry dynamoDbLockRegistry(AmazonDynamoDB amazonDynamoDb) {
var lockClientOptions = dynamoDBLockClientOptionsBuilder(amazonDynamoDb).build();
return new DynamoDbLockRegistry(new AmazonDynamoDBLockClient(lockClientOptions));
}
@Bean
public CommandLineRunner runner(AmazonDynamoDB amazonDynamoDb, DynamoDbLockRegistry dynamoDbLockRegistry) {
return args -> {
createAbandonedLock(amazonDynamoDb);
logger.info("Trying to acquire the abandoned lock");
var lock = dynamoDbLockRegistry.obtain(PARTITION_KEY);
while (!lock.tryLock()) {
logger.info("Failed to lock");
Thread.sleep(1000);
}
logger.info("Lock is acquired");
lock.unlock();
logger.info("Done");
};
}
lock.tryLock
cycle will never end.
Expected behavior
Lock is acquired if we try more than lock's lease duration time.
Sample
I've created a sample to reproduce it https://github.com/GarryIV/kinesis-lock-bug
The code that reproduces the problem is here
To reproduce it run
docker-compose up -d
./gradlew bootRun
It's expected that "Lock is acquired
is printed after 20+ seconds bit you will see endless Failed to lock
messages.
NB: We faced this while we were trying to use spring-integration-aws:2.5.2 with the latest spring-cloud-stream-binder-kinesis
-org.springframework.cloud:spring-cloud-stream-binder-kinesis:2.2.0
.
The binder is trying to acquire a lock with no chance to success. Only way to start it is to delete lock record manually.
I also included a sample use case for it, pls check the readme.