From 696472037fd841c5e4c80f361ddc12425f22a09e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 7 Jan 2021 10:34:49 -0500 Subject: [PATCH] Handle only LockNotGrantedException for heartbeat If we don't have a connection to AWS or our thread is interrupted for some reason, we should just re-throw that exception as is. * Only catch a `LockNotGrantedException` which really indicates that the state of the lock record has been changed. Therefore we also have to reset local state and try again --- .../integration/aws/lock/DynamoDbLockRegistry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 0546b55..48d54a1 100644 --- a/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java +++ b/src/main/java/org/springframework/integration/aws/lock/DynamoDbLockRegistry.java @@ -56,6 +56,7 @@ import com.amazonaws.services.dynamodbv2.model.BillingMode; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; +import com.amazonaws.services.dynamodbv2.model.LockNotGrantedException; import com.amazonaws.services.dynamodbv2.model.LockTableDoesNotExistException; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.ResourceInUseException; @@ -532,7 +533,7 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing this.lockItem.sendHeartBeat(); acquired = true; } - catch (Exception e) { + catch (LockNotGrantedException ex) { // May be no lock record in the DB - discard local holder and try to lock again this.lockItem = null; }