ZooKeeper
  1. ZooKeeper
  2. ZOOKEEPER-893

ZooKeeper high cpu usage when invalid requests

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.3.1
    • Fix Version/s: 3.3.2, 3.4.0
    • Component/s: server
    • Labels:
      None
    • Environment:

      Linux 2.6.16
      4x Intel(R) Xeon(R) CPU X3320 @ 2.50GHz
      java version "1.6.0_17"
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) Server VM (build 14.3-b01, mixed mode)

    • Hadoop Flags:
      Reviewed
    • Tags:
      zookeeper server cpu ZOOKEEPER-427

      Description

      When ZooKeeper receives certain illegally formed messages on the internal communication port (:4181 by default), it's possible for ZooKeeper to enter an infinite loop which causes 100% cpu usage. It's related to ZOOKEEPER-427, but that patch does not resolve all issues.

      from: src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java

      the two affected parts:
      ===========
      int length = msgLength.getInt();
      if(length <= 0)

      { throw new IOException("Invalid packet length:" + length); }


      ===========

      ===========
      while (message.hasRemaining()) {
      temp_numbytes = channel.read(message);
      if(temp_numbytes < 0)

      { throw new IOException("Channel eof before end"); }


      numbytes += temp_numbytes;
      }
      ===========

      how to replicate this bug:

      perform an nmap portscan against your zookeeper server: "nmap -sV -n your.ip.here -p4181"
      wait for a while untill you see some messages in the logfile and then you will see 100% cpu usage. It does not recover from this situation. With my patch, it does not occur anymore

      1. ZOOKEEPER-893-3.3.patch
        5 kB
        Flavio Junqueira
      2. ZOOKEEPER-893.patch
        5 kB
        Flavio Junqueira
      3. ZOOKEEPER-893.patch
        2 kB
        Thijs Terlouw

        Issue Links

          Activity

          Hide
          Hudson added a comment -

          Integrated in ZooKeeper-trunk #972 (See https://hudson.apache.org/hudson/job/ZooKeeper-trunk/972/)
          ZOOKEEPER-893. ZooKeeper high cpu usage when invalid requests

          Show
          Hudson added a comment - Integrated in ZooKeeper-trunk #972 (See https://hudson.apache.org/hudson/job/ZooKeeper-trunk/972/ ) ZOOKEEPER-893 . ZooKeeper high cpu usage when invalid requests
          Hide
          Patrick Hunt added a comment -

          +1 Great work, thanks!

          Show
          Patrick Hunt added a comment - +1 Great work, thanks!
          Hide
          Flavio Junqueira added a comment -

          Thanks, Thijs. Adding 3.3 patch.

          Show
          Flavio Junqueira added a comment - Thanks, Thijs. Adding 3.3 patch.
          Hide
          Thijs Terlouw added a comment -

          Thanks Flavio! I have been too busy to add a testcase and yours looks great!

          Show
          Thijs Terlouw added a comment - Thanks Flavio! I have been too busy to add a testcase and yours looks great!
          Hide
          Flavio Junqueira added a comment -

          Adding a test and removing an if statement that became unnecessary with this patch from RecvWorker.run(). I'll be adding a patch for the 3.3 branch shortly.

          Show
          Flavio Junqueira added a comment - Adding a test and removing an if statement that became unnecessary with this patch from RecvWorker.run(). I'll be adding a patch for the 3.3 branch shortly.
          Hide
          Flavio Junqueira added a comment -

          Missing a test.

          Show
          Flavio Junqueira added a comment - Missing a test.
          Hide
          Thijs Terlouw added a comment -

          I'll try to write a test case, but not exactly sure yet how to integrate. Need to look at some example unit tests first

          Show
          Thijs Terlouw added a comment - I'll try to write a test case, but not exactly sure yet how to integrate. Need to look at some example unit tests first
          Hide
          Henry Robinson added a comment -

          Thanks for the patch Thijs! It looks pretty good to me - good catch.

          Do you think you might be able to write a test case that verifies correct behaviour when you send malformed messages to the control port?

          Show
          Henry Robinson added a comment - Thanks for the patch Thijs! It looks pretty good to me - good catch. Do you think you might be able to write a test case that verifies correct behaviour when you send malformed messages to the control port?
          Hide
          Thijs Terlouw added a comment -

          ZOOKEEPER-427 fixes only part of the problems and still caused problems for me. This solves all my problems

          Show
          Thijs Terlouw added a comment - ZOOKEEPER-427 fixes only part of the problems and still caused problems for me. This solves all my problems

            People

            • Assignee:
              Thijs Terlouw
              Reporter:
              Thijs Terlouw
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development