Pub/Sub in a concurrent scenario may result in the inability to use subscriptions anymore, which can ultimately lead to memory leaks #3080
Labels
status: waiting-for-triage
An issue we've not yet triaged
Uh oh!
There was an error while loading. Please reload this page.
Problem Description
Code Execution Process
addListener Method
listenerTopics
collection.subscribeChannel
method is invoked to establish the subscription.org.springframework.data.redis.connection.util.AbstractSubscription#subscribe Method
alive
flag is set to true. If it is not, aRedisInvalidSubscriptionException
is thrown.removeMessageListener Method
listenerTopics
collection.listenerTopics
is empty. If so, thestopListening
method is called.closeIfUnsubscribed
method is invoked.org.springframework.data.redis.connection.util.AbstractSubscription#closeIfUnsubscribed Method
alive
flag is set to false usingalive.compareAndSet(true, false)
.Bug Analysis
removeMessageListener
method introduce a potential race condition. During the interval between these steps, it is possible for step 2 to detect thatlistenerTopics
is not empty while step 3 detects that the channel is empty (resulting in settingalive
to false).addListener
will fail because the subscription process is deemed unsuccessful. As a result, applications typically do not invokeremoveMessageListener
again, leading to the listener remaining in thelistenerTopics
collection indefinitely.Reproduction
Modify Code (RedisMessageListenerContainer)
addListener
executes successfully and promptly.addListener
experiences a delay between Step 1 and Step 2. Execution resumes after the first call toremoveMessageListener
.Add test case to RedisMessageListenerContainerIntegrationTests
The text was updated successfully, but these errors were encountered: