Author Ron Frederick
Recipients Ron Frederick, asvetlov, yselivanov
Date 2019-10-19.18:40:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571510429.0.0.996597968813.issue38529@roundup.psfhosted.org>
In-reply-to
Content
In testing AsyncSSH against Python 3.8, I noticed a large number of the following errors, even though I was properly closing streams before the objects holding them were garbage-collected.

    An open stream object is being garbage collected; call "stream.close()" explicitly.

After some investigation, the problem appears to be that closing a stream is not good enough to prevent the error. The check in asyncio doesn't properly handle the case where the stream is closing, but has not fully closed. Here's a simple test program that demonstrates this:

import asyncio

async def tcp_client():
    reader, writer = await asyncio.open_connection('127.0.0.1', 22)

    writer.close()

asyncio.run(tcp_client())

It's possible to avoid this message by awaiting on writer.wait_closed(), but wait_closed() doesn't exist until Python 3.7, making it very difficult to write portable code and still avoid this message.
History
Date User Action Args
2019-10-19 18:40:29Ron Fredericksetrecipients: + Ron Frederick, asvetlov, yselivanov
2019-10-19 18:40:28Ron Fredericksetmessageid: <1571510429.0.0.996597968813.issue38529@roundup.psfhosted.org>
2019-10-19 18:40:28Ron Fredericklinkissue38529 messages
2019-10-19 18:40:28Ron Frederickcreate