Title: StreamWriter.wait_closed() can hang indefinitely.
Type: behavior Stage:
Components: asyncio Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: François Voron, asvetlov, mdk, r3owen, tomchristie, yselivanov
Priority: normal Keywords:

Created on 2020-02-26 10:36 by tomchristie, last changed 2021-02-25 00:16 by r3owen.

Messages (4)
msg362688 - (view) Author: Tom Christie (tomchristie) * Date: 2020-02-26 10:36
Raising an issue that's impacting us on `httpx`.

It appears that in some cases SSL unwrapping can cause `.wait_closed()` to hang indefinately.

Trio are particularly careful to work around this case, and have an extensive comment on it: 

Originally raised via

Tested on:

* Python 3.7.6
* Python 3.8.1

import asyncio
import ssl
import certifi

hostname = ''
context = ssl.create_default_context()

async def main():
    reader, writer = await asyncio.open_connection(hostname, 443, ssl=context)
    print('close started')
    await writer.wait_closed()
    print('close completed')
msg362738 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2020-02-26 21:02
Can reproduce in:

- 3.8.0
- 3.8.2
- 3.7.6
msg387644 - (view) Author: Russell Owen (r3owen) * Date: 2021-02-25 00:15
I am also seeing this in Python 3.8.6. I am not using SSL, but am simply calling `await writer.wait_closed()` on an `asyncio.StreamWriter`. Sometimes it works quickly and sometimes it hangs indefinitely.
msg387645 - (view) Author: Russell Owen (r3owen) * Date: 2021-02-25 00:16
Regarding my previous comment: I have never seen this in Python 3.7 (though I see that this particular bug is listed as being present there) so it may be a different underlying issue.
Date User Action Args
2021-02-25 00:16:14r3owensetmessages: + msg387645
2021-02-25 00:15:11r3owensetnosy: + r3owen
messages: + msg387644
2020-02-26 21:02:09mdksetnosy: + mdk
messages: + msg362738
2020-02-26 10:53:32François Voronsetnosy: + François Voron

title: StreamWriter.wait_closed() can hang indefinately. -> StreamWriter.wait_closed() can hang indefinitely.
2020-02-26 10:36:06tomchristiecreate