Issue 25441: StreamWriter.drain() unreliably reports closed sockets (original) (raw)
This issue has been migrated to GitHub: https://github.com/python/cpython/issues/69627
classification
Title: | StreamWriter.drain() unreliably reports closed sockets | ||
---|---|---|---|
Type: | Stage: | ||
Components: | asyncio | Versions: | Python 3.6, Python 3.4, Python 3.5 |
process
Status: | closed | Resolution: | fixed |
---|---|---|---|
Dependencies: | Superseder: | ||
Assigned To: | gvanrossum | Nosy List: | gvanrossum, python-dev, sebastien.bourdeauducq, vstinner, yselivanov |
Priority: | normal | Keywords: |
Created on 2015-10-19 14:12 by sebastien.bourdeauducq, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (5) | ||
---|---|---|
msg253181 - (view) | Author: Sebastien Bourdeauducq (sebastien.bourdeauducq) * | Date: 2015-10-19 14:12 |
1. Open a listening socket: $ nc6 -l -p 1066 2. Run the following (tested here on Linux): import asyncio async def bug(): reader, writer = await asyncio.open_connection("::1", "1066") while True: writer.write("foo\n".encode()) await writer.drain() # Uncommenting this makes drain() raise BrokenPipeError # when the server closes the connection. #await asyncio.sleep(0.1) loop = asyncio.get_event_loop() loop.run_until_complete(bug()) 3. Terminate netcat with Ctrl-C. The program will go on a endless loop of "socket.send() raised exception." as writer.drain() fails to raise an exception to report the closed connection. Reducing the output rate of the program by using asyncio.sleep causes writer.drain() to raise BrokenPipeError (and shouldn't it be ConnectionResetError?) | ||
msg253182 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2015-10-19 14:46 |
See also this upstream git issue: https://github.com/python/asyncio/issues/263. Let me know whether the patch suggested there works for you, and I'll prioritize getting it checked in. (Help would also be appreciated, e.g. in the form of a unittest.) | ||
msg253184 - (view) | Author: Sebastien Bourdeauducq (sebastien.bourdeauducq) * | Date: 2015-10-19 16:19 |
Yes, this patch fixes the problem (in both this example and my real application). Thanks! | ||
msg253186 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2015-10-19 19:02 |
Fixed by 17f76258d11d, d30fbc55194d and 08adb4056b5f. | ||
msg253187 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2015-10-19 19:10 |
New changeset 17f76258d11d by Guido van Rossum in branch '3.4': Issue #25441: asyncio: Raise error from drain() when socket is closed. https://hg.python.org/cpython/rev/17f76258d11d New changeset d30fbc55194d by Guido van Rossum in branch '3.5': Issue #25441: asyncio: Raise error from drain() when socket is closed. (Merge 3.4->3.5) https://hg.python.org/cpython/rev/d30fbc55194d New changeset 08adb4056b5f by Guido van Rossum in branch 'default': Issue #25441: asyncio: Raise error from drain() when socket is closed. (Merge 3.5->3.6) https://hg.python.org/cpython/rev/08adb4056b5f |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:22 | admin | set | github: 69627 |
2015-10-19 19:10:21 | python-dev | set | nosy: + python-devmessages: + |
2015-10-19 19:02:16 | gvanrossum | set | status: open -> closedassignee: gvanrossumresolution: fixedmessages: + |
2015-10-19 16:19:53 | sebastien.bourdeauducq | set | messages: + |
2015-10-19 14:47:14 | gvanrossum | set | versions: + Python 3.4, Python 3.6 |
2015-10-19 14:46:57 | gvanrossum | set | messages: + |
2015-10-19 14:12:10 | sebastien.bourdeauducq | create |