Skip to content

Commit

Permalink
GH-3307: Retry TransTimedEx in LockRepo.acquire
Browse files Browse the repository at this point in the history
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**
  • Loading branch information
astrubel committed Jun 16, 2020
1 parent 7cefd53 commit b0cd015
Showing 1 changed file with 6 additions and 4 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
import org.springframework.dao.TransientDataAccessException;
import org.springframework.integration.support.locks.ExpirableLockRegistry;
import org.springframework.integration.util.UUIDConverter;
import org.springframework.transaction.TransactionTimedOutException;
import org.springframework.util.Assert;

/**
Expand All @@ -47,6 +48,7 @@
* @author Kai Zimmermann
* @author Bartosz Rempuszewski
* @author Gary Russell
* @author Alexandre Strubel
*
* @since 4.3
*/
Expand Down Expand Up @@ -131,7 +133,7 @@ public void lock() {
}
break;
}
catch (TransientDataAccessException e) {
catch (TransientDataAccessException | TransactionTimedOutException e) {
// try again
}
catch (InterruptedException e) {
Expand Down Expand Up @@ -165,7 +167,7 @@ public void lockInterruptibly() throws InterruptedException {
}
break;
}
catch (TransientDataAccessException e) {
catch (TransientDataAccessException | TransactionTimedOutException e) {
// try again
}
catch (InterruptedException ie) {
Expand Down Expand Up @@ -209,7 +211,7 @@ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
}
return acquired;
}
catch (TransientDataAccessException e) {
catch (TransientDataAccessException | TransactionTimedOutException e) {
// try again
}
catch (Exception e) {
Expand Down

0 comments on commit b0cd015

Please sign in to comment.