Skip to content

Commit 434817f

Browse files
astrubelartembilan
authored andcommitted
GH-3307: Retry TransTimedEx in LockRepo.acquire
Fixes #3307 The `DefaultLockRepository.acquire()` is transactional method and can fail with the `TransactionTimedOutException`. When we call `JdbcLock.lock()`, we expect an attempt until we really obtain a lock. * Treat a `TransactionTimedOutException` as a `TransientDataAccessException` and therefore retry a locking attempt logic **Cherry-pick to 5.3.x, 5.2.x & 4.3.x** (cherry picked from commit b0cd015)
1 parent 8bacf36 commit 434817f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import org.springframework.dao.TransientDataAccessException;
3232
import org.springframework.integration.support.locks.ExpirableLockRegistry;
3333
import org.springframework.integration.util.UUIDConverter;
34+
import org.springframework.transaction.TransactionTimedOutException;
3435
import org.springframework.util.Assert;
3536

3637
/**
@@ -47,6 +48,7 @@
4748
* @author Kai Zimmermann
4849
* @author Bartosz Rempuszewski
4950
* @author Gary Russell
51+
* @author Alexandre Strubel
5052
*
5153
* @since 4.3
5254
*/
@@ -131,7 +133,7 @@ public void lock() {
131133
}
132134
break;
133135
}
134-
catch (TransientDataAccessException e) {
136+
catch (TransientDataAccessException | TransactionTimedOutException e) {
135137
// try again
136138
}
137139
catch (InterruptedException e) {
@@ -165,7 +167,7 @@ public void lockInterruptibly() throws InterruptedException {
165167
}
166168
break;
167169
}
168-
catch (TransientDataAccessException e) {
170+
catch (TransientDataAccessException | TransactionTimedOutException e) {
169171
// try again
170172
}
171173
catch (InterruptedException ie) {
@@ -209,7 +211,7 @@ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
209211
}
210212
return acquired;
211213
}
212-
catch (TransientDataAccessException e) {
214+
catch (TransientDataAccessException | TransactionTimedOutException e) {
213215
// try again
214216
}
215217
catch (Exception e) {

0 commit comments

Comments
 (0)