STINNER Victor <vstin...@redhat.com> added the comment:

Update:

* 
test.test_asyncio.test_sendfile.ProactorEventLoopTests.test_sendfile_close_peer_in_the_middle_of_receiving
 leaks 1 reference per run: this bug is caused by bpo-35682 and fixed by PR 
11462
* 
test.test_asyncio.test_sendfile.ProactorEventLoopTests.test_sendfile_fallback_close_peer_in_the_middle_of_receiving
 leaks 1 reference per run: I don't understand why.

I spent a lot of time to investigate 
test_sendfile_fallback_close_peer_in_the_middle_of_receiving() leak and I don't 
understand the issue. The main loop is BaseEventLoop._sendfile_fallback(). For 
the specific case of this test, the loop can be simplified to:

        proto = _SendfileFallbackProtocol(transp)
        try:
            while True:
                data = b'x' * (1024 * 64)
                await proto.drain()
                transp.write(data)
        finally:
            await proto.restore()

The server closes the connection after it gets 1024 bytes. The client socket 
gets a ConnectionAbortedError exception in 
_ProactorBaseWritePipeTransport._loop_writing() which calls _fatal_error():

        except OSError as exc:
            self._fatal_error(exc, 'Fatal write error on pipe transport')

_fatal_error() calls _force_close() which sets _closing to True and calls 
protocol.connection_lost(). In the meanwhile, drain() raises ConnectionError 
because is_closing() is true:

    async def drain(self):
        if self._transport.is_closing():
            raise ConnectionError("Connection closed by peer")
        ...

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32710>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to