Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-13971

Atomicity violations caused by improper usage of ConcurrentHashMap

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.4.0
    • None

    Description

      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().

      Attachments

        Activity

          People

            Kvicii Kvicii.Yu
            divijvaidya Divij Vaidya
            Chris Egerton Chris Egerton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: