edgedb / edgedb-java

The official Java client library for EdgeDB
Apache License 2.0
19 stars 4 forks source link

Fix data issues when spanning >16k bytes #16

Closed quinchs closed 1 year ago

quinchs commented 1 year ago

Summary

Netty transfers data to the binding in chunks of <=16k bytes at a time, the EdgeDB protocol can have messages with lengths over that size, therefor the binding must collect the chunks to build a complete message if the protocol message is >16k bytes.

The binding did attempt to do this with a contract structure, creating PacketContracts for messages that can't be read with the provided buffer, ref:

https://github.com/edgedb/edgedb-java/blob/abb7f8a797e0d2ec21c0ee4ba298022fa2cf06a9/src/driver/src/main/java/com/edgedb/driver/binary/PacketSerializer.java#L77-L98

although, this code failed to account for successful contracts with remaining data, ignoring it and misreading the protocol data.

This PR fixes that by correctly consuming the remaining data of a completed contract, as well as correctly handling cases where multiple chunks are sent for one large data message.

quinchs commented 1 year ago

Fixes #15

scotttrinh commented 1 year ago

I'm not familiar enough with how the Contract pattern works here to comment on the actual logic, but it would be helpful to see a test that exercised this 16k message with something simple like a select on a 16k string full of a or something obvious like that. Is that straightforward to add?

quinchs commented 1 year ago

Added tests for both multiple data packets spanning >16k and one data packet with a size over >16k