You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Chris Egerton (Jira)" <ji...@apache.org> on 2022/08/23 14:26:00 UTC

[jira] [Resolved] (KAFKA-13971) Atomicity violations caused by improper usage of ConcurrentHashMap

     [ https://issues.apache.org/jira/browse/KAFKA-13971?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Chris Egerton resolved KAFKA-13971.
-----------------------------------
    Fix Version/s: 3.4.0
         Reviewer: Chris Egerton
       Resolution: Fixed

> 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
>            Assignee: Kvicii.Yu
>            Priority: Minor
>              Labels: newbee, newbie
>             Fix For: 3.4.0
>
>
> *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.10#820010)