[New-bugs-announce] [issue33662] asyncio Stream Reader Blocks on read when data fetched is less than limit

skorpeo report at bugs.python.org
Sun May 27 18:34:41 EDT 2018


New submission from skorpeo <skorpeo11 at gmail.com>:

I humbly submit what I think may be a bug in the asyncio.StreamReader.read() function.  When n=-1 is supplied and the data is less than self._limit the read function creates a future and never wakes it up.  I believe the culprit is https://github.com/python/cpython/blob/9d3627e311211a1b4abcda29c36fe4afe2c46532/Lib/asyncio/streams.py#L632.  To fix the issue a condition is added to break out of the loop if the data read is less than the limit.  I can only attach one file so I am providing the fix here for asyncio streams.py:  

blocks.append(block)           # existing
if len(block) < self._limit:   # new
    break                      # new

I have also attached a test file that shows the blocking behavior which is alleviated with the above fix.  Finally, I am not sure how to handle a situation where the data is exactly equal to the limit and no subsequent data is sent.

----------
components: asyncio
files: pty_test.py
messages: 317810
nosy: asvetlov, skorpeo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio Stream Reader Blocks on read when data fetched is less than limit
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47615/pty_test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33662>
_______________________________________


More information about the New-bugs-announce mailing list