This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Control flow inconsistency on closed asyncio stream
Type: behavior Stage:
Components: asyncio, Windows Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, eamanu, paul.moore, schlamar, steve.dower, tim.golden, yselivanov, zach.ware
Priority: normal Keywords:

Created on 2019-01-28 07:54 by schlamar, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
tcp_test.py schlamar, 2019-01-28 07:54
tcp_test.py schlamar, 2019-02-21 18:46
Messages (5)
msg334450 - (view) Author: Marc Schlaich (schlamar) * Date: 2019-01-28 07:54
After closing a StreamWriter the `StreamReaderProtocol.connection_lost` on the other end is not getting called. In this case the StreamReader is at EOF but calling write/drain does not raise any Exception (and sending data to Nirvana). 

I would expect that StreamWriter.is_closing returns True after the close and calling write/drain raises immediately and not just after the second call. Please see attached example. I see the same behavior with Proactor and Selector event loop on Windows.

Maybe this is expected behavior. But in this case it is completely undocumented. Should there be a check for `StreamReader.at_eof` (and maybe `StreamReader.exception`) before writing to the StreamWriter?

This might be related to bpo-34176.
msg334453 - (view) Author: Marc Schlaich (schlamar) * Date: 2019-01-28 09:02
After having a closer look I fear that there isn't a correct implementation for half closed sockets and returning True from eof_received results in a fundamentally broken state machine.

I'm not sure if a selector implementation can handle half closed sockets, at least I'm pretty sure that this is not supported on Windows (https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-select).
msg336144 - (view) Author: Emmanuel Arias (eamanu) * Date: 2019-02-20 19:53
I think that this issue is just for Windows right?

I add Windows to required a Windows' dev.
msg336252 - (view) Author: Marc Schlaich (schlamar) * Date: 2019-02-21 18:46
No, I'm seeing the same issue on MacOS. Attached modified example.
msg336548 - (view) Author: Emmanuel Arias (eamanu) * Date: 2019-02-25 18:57
Ok, I am working on that.
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 80021
2019-02-25 18:57:20eamanusetmessages: + msg336548
2019-02-21 18:46:17schlamarsetfiles: + tcp_test.py

messages: + msg336252
2019-02-20 19:53:36eamanusetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg336144
components: + Windows
2019-02-20 10:48:50eamanusetnosy: + eamanu
2019-01-28 09:02:20schlamarsetmessages: + msg334453
2019-01-28 07:54:05schlamarcreate