Lawouach/WebSocket-for-Python — Issue #20: memory leak
Author: tweber
Created: 2012-02-09 17:22:57+00:00
State: open

The server has a memory leak. I found it because my server ran out of memory after several thousand clients connected and disconnected. I verified the leak using Python objgraph pypi.python.org/pypi/objgraph . It appears that for every websocket connection, two generators, one Stream, and one Frame are leaked. Even after the connection is closed, these objects remain in memory. Even after garbage collection. To verify it, add the following two lines to the sample echo server.

for x in ['generator', 'Stream', 'Frame', 'TextMessage']:
print x, len(objgraph.by_type(x))

Now connect and disconnect several clients. You will see the number of instances of these objects climb, even after all clients are disconnected, even after garbage collection.

I use geventserver. I have not tried with the other servers. But there is no leakage of Greenlets, so I suspect the issue is not related to gevent.