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

Unsafe publication in client API

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.2.2
    • Fix Version/s: 3.8.0
    • Component/s: java client
    • Labels:
      None

      Description

      The following code may result in a data race due to unsafe publication of a reference to "this". The call to cnxn.start() spawns threads that have access to the partially-constructed reference to the ZooKeeper object.

      See http://www.ibm.com/developerworks/java/library/j-jtp0618.html for some background info.

      public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher)
          throws IOException
      {
              .....
              cnxn = new ClientCnxn(connectString, sessionTimeout, this, watchManager);
              cnxn.start();
      }
      

      The obvious fix is to move the call to cnxn.start() into a separate start() method.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                martint Martin Traverso
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: