Skip to content

GH-3716: Fix wait for init redisMessageListenerContainer #3719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2022

Conversation

Meteorkor
Copy link
Contributor

Fix wait for init redisMessageListenerContainer

Container A, Request to LockA -> redisMessageListenerContainer is starting (not done)
Container B, Request to LockB, obtain Lock
Container A, Request to LockB -> subscribeUnlock(wait unlock msg), but redisMessageListenerContainer is not done
Container B, Request to LockB, unlock LockB and publish unlockMsg(LockB), but Container A not received

#3716 (comment)

to-be
If the redisMessageListenerContainer is starting, Waiting for redisMessageListenerContainer to complete without doing subscribeUnlock()

RedisLockRegistry.this.redisMessageListenerContainer.afterPropertiesSet();
RedisLockRegistry.this.redisMessageListenerContainer.start();
if (!(RedisLockRegistry.this.isRunningRedisMessageListenerContainer
&& RedisLockRegistry.this.redisMessageListenerContainer.isRunning())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just one our isRunningRedisMessageListenerContainer is enough.
The problem is really that RedisMessageListenerContainer sets running = true; in the beginning of start().
Better to have it in the end, when subscription is ready.
But still we need that synchronized (RedisLockRegistry.this.redisMessageListenerContainer) anyway to block any concurrent calls for the start().

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is really that RedisMessageListenerContainer sets running = true; in the beginning of start().

I agree with what you said.
However, it was thought that it would be difficult to change that part in spring-integration, so I modified the code to handle it.

The reason to check both is because there is a code that sets running = false;
(isRunningRedisMessageListenerContainer and redisMessageListenerContainer.isRunning())
when an error occurs in redisMessageListenerContainer.start(), but will be not threw Exception.
(https://github.com/spring-projects/spring-data-redis/blob/main/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java#L222)

There is almost no failure, but if it fails, it looks like we will have to run start() again, so I'm checking both.

@artembilan artembilan merged commit 291fe34 into spring-projects:main Feb 8, 2022
@artembilan
Copy link
Member

... and cherry-picked to 5.5.x.

@Meteorkor ,

thank you as usual for great and thoughtful work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants