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

Ephemeral znode will not be removed when sesstion timeout, if the system time of ZooKeeper node changes unexpectedly.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.8, 3.4.9, 3.4.10
    • 3.4.11
    • server
    • None
    • Centos6.5

    Description

      1. Deploy a ZooKeeper cluster with one node.
      2. Create a Ephemeral znode.
      3. Change the system time of the ZooKeeper node to a earlier point.
      4. Disconnect the client with the ZooKeeper server.

      Then the ephemeral znode will exist for a long time even when session timeout.

      I have read the ZooKeeper source code and I find the code int SessionTrackerImpl.java,

      SessionTrackerImpl.java
          @Override
          synchronized public void run() {
              try {
                  while (running) {
                      currentTime = System.currentTimeMillis();
                      if (nextExpirationTime > currentTime) {
                          this.wait(nextExpirationTime - currentTime);
                          continue;
                      }
                      SessionSet set;
                      set = sessionSets.remove(nextExpirationTime);
                      if (set != null) {
                          for (SessionImpl s : set.sessions) {
                              setSessionClosing(s.sessionId);
                              expirer.expire(s);
                          }
                      }
                      nextExpirationTime += expirationInterval;
                  }
              } catch (InterruptedException e) {
                  handleException(this.getName(), e);
              }
              LOG.info("SessionTrackerImpl exited loop!");
          }
      

      I think it may be better to use System.nanoTime(), not System.currentTimeMillis, because the later can be changed manually or automatically by a NTP client.

      Attachments

        Issue Links

          Activity

            People

              jiangjiafu Jiafu Jiang
              jiangjiafu Jiafu Jiang
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: