From 99423c0c8493e7149e0ff53da12ff57cecd75ffe Mon Sep 17 00:00:00 2001 From: "Mark E. Haase" Date: Thu, 4 Jun 2020 09:46:51 -0400 Subject: [PATCH] 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. --- rethinkdb/trio_net/net_trio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rethinkdb/trio_net/net_trio.py b/rethinkdb/trio_net/net_trio.py index 8eb7fbe8..6ac42df2 100644 --- a/rethinkdb/trio_net/net_trio.py +++ b/rethinkdb/trio_net/net_trio.py @@ -237,8 +237,11 @@ async def _read_until(self, delimiter): return bytes(buffer) async def _read_exactly(self, num): + data = b'' try: - return await self._stream.receive_some(num) + while len(data) < num: + data += await self._stream.receive_some(num - len(data)) + return data except (trio.BrokenResourceError, trio.ClosedResourceError): self._closed = True