Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.8.4, 3.9.2
-
None
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