INT-4447: LockRegLeaderInit: Catch unlock errors
JIRA: https://jira.spring.io/browse/INT-4447 When we get an exception during `this.lock.unlock()`, we don't revoke leadership. In case of external resource (e.g. JDBC) this may cause a race condition when the second candidate is selected as leader when connection comes back * Catch `this.lock.unlock()` exceptions and log them under DEBUG. This way we proceed to the `handleRevoked()` logic **Cherry-pick to 5.0.x and 4.3.x** # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java
This commit is contained in:
@@ -163,6 +163,35 @@ public class JdbcLockRegistryLeaderInitiatorTests {
|
||||
initiator1.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLostConnection() throws InterruptedException {
|
||||
CountDownLatch granted = new CountDownLatch(1);
|
||||
CountingPublisher countingPublisher = new CountingPublisher(granted);
|
||||
|
||||
DefaultLockRepository lockRepository = new DefaultLockRepository(dataSource);
|
||||
lockRepository.afterPropertiesSet();
|
||||
LockRegistryLeaderInitiator initiator = new LockRegistryLeaderInitiator(new JdbcLockRegistry(lockRepository));
|
||||
initiator.setLeaderEventPublisher(countingPublisher);
|
||||
|
||||
initiator.start();
|
||||
|
||||
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
|
||||
|
||||
destroy();
|
||||
|
||||
assertThat(countingPublisher.revoked.await(10, TimeUnit.SECONDS), is(true));
|
||||
|
||||
granted = new CountDownLatch(1);
|
||||
countingPublisher = new CountingPublisher(granted);
|
||||
initiator.setLeaderEventPublisher(countingPublisher);
|
||||
|
||||
init();
|
||||
|
||||
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
|
||||
|
||||
initiator.stop();
|
||||
}
|
||||
|
||||
private static class CountingPublisher implements LeaderEventPublisher {
|
||||
|
||||
private CountDownLatch granted;
|
||||
|
||||
Reference in New Issue
Block a user