Skip to content

Conversation

tbarabanov
Copy link
Contributor

Fixes possible ConcurrentModificationException in KafkaMessageListenerContainer that can happen in case if any of partitionsListenerConsumer.definedPartitions or partitionsListenerConsumer.assignedPartitions fields are being iterated/modified simultaneously.

For instance by consumer thread performing rebalancing and arbitrary application thread calling getAssignedPartitions method in KafkaMessageListenerContainer.

To achieve desired effect I'm using synchronized wrappers. I would prefer modern concurrent collections such as ConcurrentHashMap, but definedPartitions field has type of LinkedHashMap and its keySet preserves keys order.
Thus 1) no thread safe data structures available from std lib with same characteristics 2) possibly some users rely on the order. Anyway do not think that there are real life cases that can put definedPartitions or assignedPartitions under pressure.

Fixes GH-3726 (#3726)

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Please, add your name to the @author list of that changed class - and I'll merge it shortly.

Thank you!

@tbarabanov
Copy link
Contributor Author

Done. Thx!

@artembilan artembilan merged commit b772ebd into spring-projects:main Jan 30, 2025
3 checks passed
@artembilan
Copy link
Member

Merged and back-ported to 3.2.x.

Thank you for contribution; looking forward for more!

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.

KafkaMessageListenerContainer.getAssignedPartitions is not safe
2 participants