From 434817fc2c5c12a367178ebb604c5681c517484c Mon Sep 17 00:00:00 2001 From: astrubel <66489232+astrubel@users.noreply.github.com> Date: Tue, 16 Jun 2020 16:18:41 +0200 Subject: [PATCH] GH-3307: Retry TransTimedEx in LockRepo.acquire Fixes https://github.com/spring-projects/spring-integration/issues/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 b0cd0156c7e7d81d87c6a94201a8172441220464) --- .../integration/jdbc/lock/JdbcLockRegistry.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java index 4a52323369..658ed302e5 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java @@ -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. @@ -31,6 +31,7 @@ import org.springframework.dao.DataAccessResourceFailureException; 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; /** @@ -47,6 +48,7 @@ import org.springframework.util.Assert; * @author Kai Zimmermann * @author Bartosz Rempuszewski * @author Gary Russell + * @author Alexandre Strubel * * @since 4.3 */ @@ -131,7 +133,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry { } break; } - catch (TransientDataAccessException e) { + catch (TransientDataAccessException | TransactionTimedOutException e) { // try again } catch (InterruptedException e) { @@ -165,7 +167,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry { } break; } - catch (TransientDataAccessException e) { + catch (TransientDataAccessException | TransactionTimedOutException e) { // try again } catch (InterruptedException ie) { @@ -209,7 +211,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry { } return acquired; } - catch (TransientDataAccessException e) { + catch (TransientDataAccessException | TransactionTimedOutException e) { // try again } catch (Exception e) {