Copilot commented on code in PR #18793:
URL: https://github.com/apache/iotdb/pull/18793#discussion_r4197134675
##########
iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TCompressedElasticFramedTransport.java:
##########
@@ -59,10 +59,14 @@ protected void closeAllocatedBuffers() {
@Override
protected void readFrame() throws TTransportException {
+ // Discard the previous frame's budget before reading the next frame
header and payload.
+ resetMessageSizeAndConsumedBytes();
underlying.readAll(i32buf, 0, 4);
int size = TFramedTransport.decodeFrameSize(i32buf);
validateFrame(size);
readBuffer.fill(underlying, size);
+ // Bind subsequent protocol reads to the current compressed frame size.
+ resetMessageSizeAndConsumedBytes(size);
Review Comment:
The compressed path has the same limit mismatch: this reset validates the
compressed frame size against the underlying endpoint's default
`maxMessageSize`, even when this transport was constructed with a larger
`thriftMaxFrameSize`. SSL/blocking endpoints using Thrift's 100 MiB default
will reject otherwise-valid larger compressed frames here. Align the underlying
endpoint configuration with IoTDB's configured frame limit before wrapping it.
##########
iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/TElasticFramedTransportTest.java:
##########
@@ -19,18 +19,85 @@
package org.apache.iotdb.rpc;
+import org.apache.thrift.TConfiguration;
import org.apache.thrift.transport.TByteBuffer;
+import org.apache.thrift.transport.TMemoryBuffer;
import org.apache.thrift.transport.TTransportException;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class TElasticFramedTransportTest {
+ @Test
+ public void testReadFramesResetMessageSize() throws TTransportException {
+ byte[] firstFrame = {1, 2};
+ byte[] secondFrame = {3, 4, 5, 6, 7, 8};
+ ByteBuffer framedData =
+ ByteBuffer.allocate(8 + firstFrame.length + secondFrame.length)
+ .putInt(firstFrame.length)
+ .put(firstFrame)
+ .putInt(secondFrame.length)
+ .put(secondFrame)
+ .flip();
+ TConfiguration configuration =
+
TConfiguration.custom().setMaxMessageSize(10).setMaxFrameSize(10).build();
+ TMemoryBuffer underlying = new TMemoryBuffer(configuration, 10);
Review Comment:
This regression test does not prove that frame budgets are reset: in Thrift
0.25, `TMemoryBuffer.read` checks each requested length but does not decrement
the remaining message budget. If both new reset calls are removed, every
individual read here is still at most 10 bytes and the test passes. Use a
budget-consuming underlying transport so the test fails against the pre-fix
implementation.
This issue also appears on line 87 of the same file.
##########
iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TElasticFramedTransport.java:
##########
@@ -194,10 +194,14 @@ public int read(byte[] buf, int off, int len) throws
TTransportException {
}
protected void readFrame() throws TTransportException {
+ // Discard the previous frame's budget before reading the next frame
header and payload.
+ resetMessageSizeAndConsumedBytes();
underlying.readAll(i32buf, 0, 4);
int size = TFramedTransport.decodeFrameSize(i32buf);
validateFrame(size);
readBuffer.fill(underlying, size);
+ // Bind subsequent protocol reads to the current frame size.
+ resetMessageSizeAndConsumedBytes(size);
Review Comment:
`resetMessageSizeAndConsumedBytes(size)` rejects sizes above the underlying
transport's `maxMessageSize`, but this wrapper's `thriftMaxFrameSize` is
configured independently. Blocking server sockets and SSL client sockets are
created with Thrift's 100 MiB default, while IoTDB clients may permit frames up
to 512 MiB, so a valid frame between those limits is read and then fails here
with `MESSAGE_SIZE_LIMIT`. Configure the endpoint message budget consistently
(including the 4-byte header) before wrapping it, or otherwise reconcile the
two limits before resetting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]