Divij Vaidya created KAFKA-13971: ------------------------------------ Summary: Atomicity violations caused by improper usage of ConcurrentHashMap Key: KAFKA-13971 URL: https://issues.apache.org/jira/browse/KAFKA-13971 Project: Kafka Issue Type: Bug Reporter: Divij Vaidya
*Code:* [https://github.com/apache/kafka/blob/trunk/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/WorkerConfigTransformer.java#L81-L84] *Problem* We are using a {{{}ConcurrentHashMap{}}}, but usage of {{{}get(){}}}, {{null}} check, and {{put()}} may not be thread-safe at lines: 81, 82, and 84. Two threads can perform this same check at the same time and one thread can overwrite the value written by the other thread. *Fix* Consider replacing {{put()}} with {{putIfAbsent()}} to help prevent accidental overwriting. {{putIfAbsent()}} puts the value only if the {{ConcurrentHashMap}} does not contain the key and therefore avoids overwriting the value written there by the other thread's {{{}putIfAbsent(){}}}. -- This message was sent by Atlassian Jira (v8.20.7#820007)