Skip to content

Commit 99423c0

Browse files
committed
Fix bug in Trio's _read_exactly()
This method calls Trio's `receive_some(n)`, which I found out can actually return fewer than `n` bytes. This is only noticeable on large messages (query results of around 80KB triggered the issue). The solution is to call `receive_some(...)` in a loop until `n` bytes has been received.
1 parent a18e756 commit 99423c0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rethinkdb/trio_net/net_trio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ async def _read_until(self, delimiter):
237237
return bytes(buffer)
238238

239239
async def _read_exactly(self, num):
240+
data = b''
240241
try:
241-
return await self._stream.receive_some(num)
242+
while len(data) < num:
243+
data += await self._stream.receive_some(num - len(data))
244+
return data
242245
except (trio.BrokenResourceError, trio.ClosedResourceError):
243246
self._closed = True
244247

0 commit comments

Comments
 (0)