[ 
https://issues.apache.org/jira/browse/KAFKA-9668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17052555#comment-17052555
 ] 

ASF GitHub Bot commented on KAFKA-9668:
---------------------------------------

big-andy-coates commented on pull request #8233: KAFKA-9668: Iterating over 
KafkaStreams.getAllMetadata() results in ConcurrentModificationException
URL: https://github.com/apache/kafka/pull/8233
 
 
   Fixes [KAFKA-9668](https://issues.apache.org/jira/browse/KAFKA-9668)
   
   `KafkaStreams.getAllMetadata()` returns 
`StreamsMetadataState.getAllMetadata()`. All the latter methods is 
`synchronized` it returns a reference to internal mutable state.  Not only does 
this break encapsulation, but it means any thread iterating over the returned 
collection when the metadata gets rebuilt will encounter a 
`ConcurrentModificationException`.
   
   This change:
    * switches from clearing and rebuild `allMetadata` when `onChange` is 
called to building a new list and swapping this in. This is thread safe and has 
the benefit that the returned list is not empty during a rebuild: you either 
get the old or the new list.
    * removes synchronisation from `getAllMetadata` and `getLocalMetadata`. 
These are returning member variables. Synchronisation adds nothing.
    * changes `getAllMetadata` to wrap its return value in an unmodifiable 
wrapper to avoid breaking encapsulation.
    * changes the getters in `StreamsMetadata` to wrap their return values in 
unmodifiable wrapper to avoid breaking encapsulation.
   
   Unit tests have been added to cover both changes classes to ensure 
encapsulation and thread-safety are maintained.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Iterating over KafkaStreams.getAllMetadata() results in 
> ConcurrentModificationException
> ---------------------------------------------------------------------------------------
>
>                 Key: KAFKA-9668
>                 URL: https://issues.apache.org/jira/browse/KAFKA-9668
>             Project: Kafka
>          Issue Type: Bug
>          Components: streams
>    Affects Versions: 0.10.1.0
>            Reporter: Andy Coates
>            Assignee: Andy Coates
>            Priority: Major
>
> `KafkaStreams.getAllMetadata()` returns 
> `StreamsMetadataState.getAllMetadata()`. All the latter methods is 
> `synchronized` it returns a reference to internal mutable state.  Not only 
> does this break encapsulation, but it means any thread iterating over the 
> returned collection when the metadata gets rebuilt will encounter a 
> `ConcurrentModificationException`.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to