Uploaded image for project: 'Slider'
  1. Slider
  2. SLIDER-1242

Review uses of double-checked locking

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • Slider 1.0.0
    • None
    • None

    Description

      There are several places where we perform double-checked locking. Even though the practice is discouraged, I believe it is technically correct when the check is performed on the presence of a ConcurrentHashMap key, which is how we are using it.

      However, in two places, AgentProviderService#getCurrentExports and AgentProviderService#getAllocatedPorts, containsKey is used instead of get to perform the check. I am seeing some indication that containsKey is not sufficient, and that get must be used for double-checked locking to be correct. There is a comment in the ConcurrentHashMap#containsKey method that says "same as get() except no need for volatile value read" – and I think that volatile value read is what we need for correctness.

      Also, in the ConcurrentHashMap api doc, it specifically mentions get and does not mention containsKey: "Any non-null result returned from get(key) and related access methods bears a happens-before relation with the associated insertion or update" and "an update operation for a given key bears a happens-before relation with any (non-null) retrieval for that key reporting the updated value."

      Attachments

        1. SLIDER-1242.1.patch
          1 kB
          Billie Rinaldi

        Activity

          People

            billie Billie Rinaldi
            billie Billie Rinaldi
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: