Asyncio based websocket client leaking memory
See original GitHub issueHey,
I use the asyncio based websocket client on windows/python3.6 for messaging between my client and the server.
Whenever the connection is closed, I instruct my client to reconnect. When that happens, I get one extra thread and memory usage. Threads stop expanding after a while (I think it’s just windows not properly reporting the threads), but memory consumption goes way up.
To reproduce the problem is pretty easy: set up an asyncio based websocket client, and tell it to reconnect with loop.create_connection
in its protocol onClose
method.
It happens when I get the following reason
in the onClose
method: connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
Please investigate. I have played around with the garbage collector and tracemalloc, it shows that the most memory consumption happens at protocol init where there’s self.is_closed = txaio.create_future()
, and after that I gave up tracking the memory leak further.
What it seems to me, is that the protocol class itself is not freed after connection close, but I can’t really tell why. I don’t keep references to the protocol class.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (3 by maintainers)
Top GitHub Comments
@meejah If my opinion counts, I’d raise that exception at the code I pointed out. The same happens with normal sockets, you get an exception when you try to send over a closed socket.
On the WAMP side, we do raise
TransportLost
if you try to send a message on a WAMP session that is not “open” … https://github.com/crossbario/autobahn-python/blob/master/autobahn/wamp/websocket.py#L126@oberstet what about changing pure WebSockets to do this (possibly “instead?” i.e. just move this to the lower layer). This would be an API change, really (i.e. “raise instead of just returning None”) not sure how to handle that properly 😕 or maybe since “it might raise an exception anyway” that’s fine?