diff --git a/aiohttp/streams.py b/aiohttp/streams.py index 4bb96ab6e82..412e2002f30 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -362,7 +362,10 @@ async def read(self, n: int=-1) -> bytes: blocks.append(block) return b''.join(blocks) - if not self._buffer and not self._eof: + # TODO: should be `if` instead of `while` + # because waiter maybe triggered on chunk end, + # without feeding any data + while not self._buffer and not self._eof: await self._wait('read') return self._read_nowait(n) @@ -371,7 +374,10 @@ async def readany(self) -> bytes: if self._exception is not None: raise self._exception - if not self._buffer and not self._eof: + # TODO: should be `if` instead of `while` + # because waiter maybe triggered on chunk end, + # without feeding any data + while not self._buffer and not self._eof: await self._wait('readany') return self._read_nowait(-1)