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

ZooKeeper.close() would leak SendThread when the network is broken

    XMLWordPrintableJSON

Details

    Description

      The close method of ZooKeeper may cause the leak of SendThread when the network is broken.

      When the network is broken, the SendThread of ZooKeeper client falls into the continuous reconnecting scenario. But there is an unsafe point which is just at the moment before startConnect() during the continuous reconnecting. If SendThread.close() in another thread hit the unsafe point, startConnect() would sleep some time and force to change state to States.CONNECTING although SendThread.close() already set state to States.CLOSED. In this case, the SendThread would be never be dead and nobody would change the state again.

      In normal case, ZooKeeper.close() would be blocked forever to wait closeSession packet is finished until the network broken is recovered. But if user set the request timeout, ZooKeeper.close() would break the block waiting within timeout and invoke SendThread.close() to change state to CLOSED. That's why SendThread.close() can hit the unsafe point.

      Set request timeout is a very common practice. 

      I propose a patch and send it out later.

      Maybe someone can help to review it.

       

      Thanks

       

       

      Attachments

        Issue Links

          Activity

            People

              yfx416 Pierre Yin
              yfx416 Pierre Yin
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10h 10m
                  10h 10m