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

Racy implicit ZKDatabase creation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.4.8
    • None
    • server
    • None

    Description

      The NIOServerCnxnFactory#startup method first starts the acceptor thread and then initialises the ZooKeeperServer instance. In particular, the call to ZooKeeperServer#startdata method creates the ZKDatabase if it does not already exist.

      This creates a race-condition: if the acceptor thread accepts an incoming connection before the ZKDatabase is established then there is a NullPointerException:

      java.lang.NullPointerException: null
      	at org.apache.zookeeper.server.ZooKeeperServer.processConnectRequest(ZooKeeperServer.java:864) ~[zookeeper-3.4.8.jar:3.4.8--1]
      	at org.apache.zookeeper.server.NIOServerCnxn.readConnectRequest(NIOServerCnxn.java:418) ~[zookeeper-3.4.8.jar:3.4.8--1]
      	at org.apache.zookeeper.server.NIOServerCnxn.readPayload(NIOServerCnxn.java:198) ~[zookeeper-3.4.8.jar:3.4.8--1]
      	at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:244) ~[zookeeper-3.4.8.jar:3.4.8--1]
      	at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:203) ~[zookeeper-3.4.8.jar:3.4.8--1]
      	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
      

      The same problem appears to be present in release-3.5 and master branches.

      The naive fix would be to start the acceptor thread last in NIOServerCnxnFactory#startup, but I can't say whether this would cause any other problems.

      Attachments

        Activity

          People

            Unassigned Unassigned
            paulmillar Paul Millar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: