cjf2xn opened a new pull request, #19480: URL: https://github.com/apache/kafka/pull/19480
## Problem The `Position` class uses multi-threaded data structures and safe publication which suggests to users that it's thread safe. The `Position#merge` method is not thread-safe due to the check-then-act logic: ```java if (!partitionMap.containsKey(partition) || partitionMap.get(partition) < offset) { partitionMap.put(partition, offset); } ``` The `partitionMap`'s entry for `partition` can change between the conditional check and the `put` call. The multi-threaded unit test reproduces the problem and fails ~80% of the time without the fix. ## Solution Delegate mutation to `withComponent` which is thread-safe since it relies on `ConcurrentHashMap#compute` which uses synchronization internally to atomically execute the remapping function. -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org