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

Unsafe publication in client API

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.2.2
    • None
    • java client
    • 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

              tison Zili Chen
              martint Martin Traverso
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: