[issue41794] Memory leak in asyncio server

Bale report at bugs.python.org
Thu Sep 17 12:52:12 EDT 2020


Bale <hswhsw490 at gmail.com> added the comment:

Ok since nobody is replying, the bug seems to be that if the asyncio server sends data, and I do not use s.recv() to clear the buffer, and I use s.close() instead, a reference to handle_echo is kept and is never deleted.

Using gc.collect() does delete the leaked object. 

The socket that you use to connect to the server seems to also determine whether the bug works, like how I can not do it when I create the connection on my windows computer, but the bug is triggered when I do it on my ubuntu server. I should also mention that I am running the asyncio server on my ubuntu server, on python 3.8.

Here is output of the bug happening.
FROM CLIENT ON MY WINDOWS COMPUTER ON PY3.8:
>>> s = socket.socket()
>>> s.connect(("x.x.x.x", 8888))
>>> s.send(b"test")
4
# Wait for server to send data, but dont use s.recv(), just assume
>>> s.close()
Server output:
Received 'test' from ('x.x.x.x', 42241)
Send: 'test'
connection lost
DELETED OBJECT

After connection was lost, DELETED OBJECT was printed, so everything worked fine. But when I create the socket in a different environment, such as on ubuntu python 3.8:
Client side code (exact same as before):
>>> s = socket.socket()
>>> s.connect(("x.x.x.x", 8888))
>>> s.send(b"test")
4
# Wait for server to send data, but dont use s.recv(), just assume
>>> s.close()
Server side output:
Received 'test' from ('x.x.x.x', 42249)
Send: 'test'
connection lost

We can see that connection lost was printed, but DELETED OBJECT was not. This is evidence that there is a memory leak bug with asyncio.start_server

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41794>
_______________________________________


More information about the Python-bugs-list mailing list