Mohammad Arshad created ZOOKEEPER-4843:
------------------------------------------
Summary: Encountering an 'Unreasonable Length' error when
configuring jute.maxbuffer to 1GB or more
Key: ZOOKEEPER-4843
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4843
Project: ZooKeeper
Issue Type: Bug
Affects Versions: 3.9.2, 3.8.4
Reporter: Mohammad Arshad
Assignee: Mohammad Arshad
*Problem:*
Encountering an 'Unreasonable Length' error when configuring jute.maxbuffer to
1GB or more
{code:java}
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
{code}
*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:
{code:java}
if (len < 0 || len > maxBufferSize + extraMaxBufferSize) {
throw new IOException(UNREASONBLE_LENGTH + len);
}
{code}
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
--
This message was sent by Atlassian Jira
(v8.20.10#820010)