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

Encountering an 'Unreasonable Length' error when configuring jute.maxbuffer to 1GB or more

    XMLWordPrintableJSON

Details

    Description

      Problem:
      Encountering an 'Unreasonable Length' error when configuring jute.maxbuffer to 1GB or more

      2024-07-04 11:55:41,806 [myid:localhost:2181] - WARN  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1300] - Session 0x0 for server localhost/127.0.0.1:2181, Closing socket connection.
      Attempting reconnect except it is a SessionExpiredException.
      java.io.IOException: Unreasonable length = 16
              at org.apache.jute.BinaryInputArchive.checkLength(BinaryInputArchive.java:166)
              at org.apache.jute.BinaryInputArchive.readBuffer(BinaryInputArchive.java:127)
              at org.apache.zookeeper.proto.ConnectResponse.deserialize(ConnectResponse.java:80)
              at org.apache.zookeeper.ClientCnxnSocket.readConnectResult(ClientCnxnSocket.java:141)
              at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:86)
              at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
              at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1289)
      2024-07-04 11:55:42,567 [myid:] - INFO  [main:o.a.z.u.ServiceUtils@45] - Exiting JVM with code 0
      

      Analysis:
      If jute.maxbuffer is set to 1GB (equivalent to 1073741824 bytes), this means that both maxBufferSize and extraMaxBufferSize are also set to 1073741824.
      Even when the response size (denoted as 'len') is minimal, the following condition check still fails:

      if (len < 0 || len > maxBufferSize + extraMaxBufferSize) {
          throw new IOException(UNREASONBLE_LENGTH + len);
      }
      

      It is because (maxBufferSize + extraMaxBufferSize) overflow int MAX_VALUE and the result is a negative number.

      Solution:
      Configure jute.maxbuffer.extrasize explicitly and give a reasonable value, so that the sum of maxBufferSize and extraMaxBufferSize is less than Integer.MAX_VALUE.

      Improvement:
      While setting jute.maxbuffer to 1GB may seem unreasonable, it would be better to validate the maxBuffer and extraMaxBufferSize configuration.
      If the sum of these two values is greater than Integer.MAX_VALUE, it should be handled gracefully by setting the sum to Integer.MAX_VALUE

      Attachments

        Activity

          People

            arshad.mohammad Mohammad Arshad
            arshad.mohammad Mohammad Arshad
            Votes:
            0 Vote for this issue
            Watchers:
            2 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 - 1.5h
                1.5h