[New-bugs-announce] [issue46318] asyncio and ssl: ResourceWarning: unclosed transport

Julien Palard report at bugs.python.org
Sun Jan 9 10:04:53 EST 2022

New submission from Julien Palard <julien+python at palard.fr>:

Originally opened at: https://github.com/aio-libs/aiohttp/issues/6071


    import asyncio

    class DumbProtocol(asyncio.Protocol):
        def connection_made(self, transport):
            print("Connection made")
            self.transport = transport

        def data_received(self, data):
            print("Data received: {!r}".format(data))

    async def main():
        loop = asyncio.get_running_loop()

        for i in range(2):
            _, _ = await loop.create_connection(DumbProtocol, "python.org", 443, ssl=True)
        while True:
            print("Waiting for the server to close the connection...")
            await asyncio.sleep(10)


Using this reproducer I get a ResourceWarning:

    Data received: b"HTTP/1.0 408 Request Time-out\r\nCache-Control: no-cache\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n<html><body><h1>408 Request Time-out</h1>\nYour browser didn't send a complete request in time.\n</body></html>\n\n"
    /usr/lib/python3.9/asyncio/sslproto.py:320: ResourceWarning: unclosed transport <asyncio.sslproto._SSLProtocolTransport object at 0x7f9328214050>
      _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    Object allocated at (most recent call last):
      File "/usr/lib/python3.9/asyncio/sslproto.py", lineno 445
        self._app_transport = _SSLProtocolTransport(self._loop, self)

I can also reproduce it on current master.

components: asyncio
messages: 410156
nosy: asvetlov, mdk, yselivanov
priority: normal
severity: normal
status: open
title: asyncio and ssl: ResourceWarning: unclosed transport
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list