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

Reconfiguration of client port causes a socket leak

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.5.0
    • Fix Version/s: 3.5.2, 3.6.0
    • Component/s: quorum
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      The NIOServerCnxnFactory reconfigure method can leak server sockets, and hence make ports unusable until the JVM restarts:

      The first line of the method takes a reference to the current ServerSocketChannel and then the next line replaces it. The subsequent interactions with the server socket can fail (for example if the reconfiguration tries to bind to an in-use port). If they fail before the call to oldSS.close() then oldSS is never closed. This holds that port open forever, and prevents the user from rolling back to the previous port!

      The code from reconfigure is shown below:

      ServerSocketChannel oldSS = ss;
      try {
      this.ss = ServerSocketChannel.open();
      ss.socket().setReuseAddress(true);
      LOG.info("binding to port " + addr);
      ss.socket().bind(addr);
      ss.configureBlocking(false);
      acceptThread.setReconfiguring();
      oldSS.close();
      acceptThread.wakeupSelector();
      try

      { acceptThread.join(); }

      catch (InterruptedException e)

      { LOG.error("Error joining old acceptThread when reconfiguring client port " + e.getMessage()); }

      acceptThread = new AcceptThread(ss, addr, selectorThreads);
      acceptThread.start();
      } catch(IOException e)

      { LOG.error("Error reconfiguring client port to " + addr + " " + e.getMessage()); }

        Attachments

        1. zookeeper.patch
          6 kB
          Timothy Ward
        2. ZOOKEEPER-2366.patch
          6 kB
          Patrick Hunt
        3. ZOOKEEPER-2366.patch
          13 kB
          Flavio Junqueira
        4. ZOOKEEPER-2366.patch
          12 kB
          Flavio Junqueira
        5. ZOOKEEPER-2366.patch
          13 kB
          Flavio Junqueira
        6. ZOOKEEPER-2366.patch
          13 kB
          Flavio Junqueira
        7. ZOOKEEPER-2366.patch
          14 kB
          Flavio Junqueira
        8. ZOOKEEPER-2366.patch
          14 kB
          Flavio Junqueira

          Activity

            People

            • Assignee:
              fpj Flavio Junqueira
              Reporter:
              timothyjward Timothy Ward
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: