GH-3716 Fix wait for init redisMsgListenContainer

Fixes https://github.com/spring-projects/spring-integration/issues/3716

If the `redisMessageListenerContainer` is starting, waiting for it to complete without doing `subscribeUnlock()`

* Introduce `isRunningRedisMessageListenerContainer` state since the `running` in the `RedisMessageListenerContainer` is set in the beginning of the `start()` misleading on the concurrent calls to the `RedisLockRegistry`

**Cherry-pick to `5.5.x`**
This commit is contained in:
Unseok Kim
2022-02-09 00:08:23 +09:00
committed by Artem Bilan
parent 724f335750
commit 6f91929da3

View File

@@ -164,6 +164,7 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
private boolean executorExplicitlySet;
private volatile boolean unlinkAvailable = true;
private volatile boolean isRunningRedisMessageListenerContainer = false;
/**
* Constructs a lock registry with the default (60 second) lock expiration.
@@ -364,9 +365,9 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
return true;
}
if (!RedisLockRegistry.this.redisMessageListenerContainer.isRunning()) {
RedisLockRegistry.this.redisMessageListenerContainer.afterPropertiesSet();
RedisLockRegistry.this.redisMessageListenerContainer.start();
if (!(RedisLockRegistry.this.isRunningRedisMessageListenerContainer
&& RedisLockRegistry.this.redisMessageListenerContainer.isRunning())) {
runRedisMessageListenerContainer();
}
while (time == -1 || expiredTime >= System.currentTimeMillis()) {
try {
@@ -523,6 +524,16 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
return RedisLockRegistry.this;
}
private void runRedisMessageListenerContainer() {
synchronized (RedisLockRegistry.this.redisMessageListenerContainer) {
if (!(RedisLockRegistry.this.isRunningRedisMessageListenerContainer
&& RedisLockRegistry.this.redisMessageListenerContainer.isRunning())) {
RedisLockRegistry.this.redisMessageListenerContainer.afterPropertiesSet();
RedisLockRegistry.this.redisMessageListenerContainer.start();
RedisLockRegistry.this.isRunningRedisMessageListenerContainer = true;
}
}
}
}
private static final class RedisUnLockNotifyMessageListener implements MessageListener {