Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-1861

ConcurrentHashMap isn't used properly in QuorumCnxManager

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5.0
    • Fix Version/s: 3.5.0
    • Component/s: None
    • Labels:
      None

      Description

      queueSendMap is a ConcurrentHashMap.
      At line 210:

                  if (!queueSendMap.containsKey(sid)) {
                      queueSendMap.put(sid, new ArrayBlockingQueue<ByteBuffer>(
                              SEND_CAPACITY));
      

      By the time control enters if block, there may be another concurrent put with same sid to the ConcurrentHashMap.
      putIfAbsent() should be used.

      Similar issue occurs at line 307 as well.

        Attachments

        1. zookeeper-1861-v1.txt
          0.7 kB
          Ted Yu
        2. zookeeper-1861-v2.txt
          2 kB
          Ted Yu
        3. zookeeper-1861-v3.txt
          3 kB
          Ted Yu

          Activity

            People

            • Assignee:
              zhihyu@ebaysf.com Ted Yu
              Reporter:
              yuzhihong@gmail.com Ted Yu
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: