You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "Huizhi Lu (Jira)" <ji...@apache.org> on 2021/01/08 09:57:00 UTC
[jira] [Created] (ZOOKEEPER-4052) Failed to read large znode that
is written successfully
Huizhi Lu created ZOOKEEPER-4052:
------------------------------------
Summary: Failed to read large znode that is written successfully
Key: ZOOKEEPER-4052
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4052
Project: ZooKeeper
Issue Type: Bug
Components: java client
Affects Versions: 3.6.2, 3.6.1
Reporter: Huizhi Lu
Assignee: Huizhi Lu
h2. Description
A client would fail to read a large znode that is successfully written. The reason is the lengths of the extra fields for CreateRequest and GetDataResponse are different: GetDataResponse's extra fields have slightly more length because of the stat field. The stat field occupies more bytes in a packet.
h2. How to Reproduce
On my MacBook, the length of incoming buffer adds 84 more bytes on the original bytes data. So I try to write (1024 * 1024 - 1 - 84) bytes to ZK which is successful. And when I read it, it fails:
{code:java}
Closing socket connection. Attempting reconnect except it is a SessionExpiredException.Closing socket connection. Attempting reconnect except it is a SessionExpiredException.java.io.IOException: Packet len 1048606 is out of range! at org.apache.zookeeper.ClientCnxnSocket.readLength(ClientCnxnSocket.java:121) at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:84) at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1275)2021-01-08 01:53:36,931 [main-EventThread] INFO org.apache.helix.zookeeper.zkclient.ZkClient - zkclient 0, zookeeper state changed ( Disconnected )
{code}
h2. Solution
We can add extra buffer size on the client based on the jute.maxbuffer, just like what has been done in BinaryInputArchive.java
{code:java}
// Since this is a rough sanity check, add some padding to maxBuffer to
// make up for extra fields, etc. (otherwise e.g. clients may be able to
// write buffers larger than we can read from disk!)
private void checkLength(int len) throws IOException {
if (len < 0 || len > maxBufferSize + extraMaxBufferSize) {
throw new IOException(UNREASONBLE_LENGTH + len);
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)