Skip to content
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

Incorrect Lock used in DefaultMessageListenerContainer #4665

Closed
w0r1t opened this issue Mar 19, 2024 · 1 comment
Closed

Incorrect Lock used in DefaultMessageListenerContainer #4665

w0r1t opened this issue Mar 19, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@w0r1t
Copy link

w0r1t commented Mar 19, 2024

Calling the DefaultMessageListenerContainer#remove(Subscription) method from multiple threads results in ConcurrentModificationException within the LinkedHashIterator. This issue arises due to the use of a read lock during collection modification.

The changes made in Pull Request #4431 are the cause of this issue. Class members lifecycleWrite and subscriptionWrite are assigned a read lock, not a write lock.

private final Lock lifecycleWrite = Lock.of(lifecycleMonitor.readLock());
private final Lock subscriptionWrite = Lock.of(subscriptionMonitor.readLock());

Exception stacktrace:

java.util.ConcurrentModificationException: null     
at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:764) ~[na:na]     
at java.base/java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:791) ~[na:na]     
at java.base/java.util.AbstractCollection.remove(AbstractCollection.java:284) ~[na:na]     
at org.springframework.data.mongodb.core.messaging.DefaultMessageListenerContainer.lambda$remove$8(DefaultMessageListenerContainer.java:203) ~[spring-data-mongodb-4.2.3.jar:4.2.3]     at org.springframework.data.util.Lock.executeWithoutResult(Lock.java:119) ~[spring-data-commons-3.2.3.jar:3.2.3]     
at org.springframework.data.mongodb.core.messaging.DefaultMessageListenerContainer.remove(DefaultMessageListenerContainer.java:195) ~[spring-data-mongodb-4.2.3.jar:4.2.3]
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2024
@mp911de mp911de self-assigned this Mar 19, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 19, 2024
@mp911de mp911de changed the title Incorrect Usage of Lock in DefaultMessageListenerContainer Incorrect Lock used in DefaultMessageListenerContainer Mar 19, 2024
@mp911de
Copy link
Member

mp911de commented Mar 19, 2024

Good catch, that's something we need to fix.

@mp911de mp911de added this to the 4.2.5 (2023.1.5) milestone Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants