You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Divij Vaidya (Jira)" <ji...@apache.org> on 2022/06/08 16:37:00 UTC
[jira] [Created] (KAFKA-13971) Atomicity violations caused by improper usage of ConcurrentHashMap
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)