Skip to content

fix memory leak - #51

Closed
net21 wants to merge 1 commit into
miguelgrinberg:masterfrom
net21:master
Closed

fix memory leak#51
net21 wants to merge 1 commit into
miguelgrinberg:masterfrom
net21:master

Conversation

@net21

@net21 net21 commented Jun 7, 2017

Copy link
Copy Markdown

the items in queue doesn't release when socket close.

@miguelgrinberg

Copy link
Copy Markdown
Owner

I don't understand the purpose of this fix. I don't believe this is a memory leak. The socket is going to close and will be deleted, and with it, the queue will be deleted as well. Or am I missing something?

@net21

net21 commented Jun 7, 2017

Copy link
Copy Markdown
Author

i use tracemalloc to trace the memory used, i emit many object to socket every second, the memory used don't released when client lose the connection, and i checked the close method is called, but the objects in queue don't released , so i have to do it .

@net21

net21 commented Jun 8, 2017

Copy link
Copy Markdown
Author

Any of the "del self.sockets[sid]" sentence in engineio\server.py wasn't be called.

@miguelgrinberg

miguelgrinberg commented Jun 8, 2017

Copy link
Copy Markdown
Owner

Any of the "del self.sockets[sid]" sentence in engineio\server.py wasn't be called.

Wouldn't that also cause the socket object and the queue to be leaked? You said just the items in the queue were leaked, or did I misunderstand?

Can you show me how did you set up your tracemalloc test?

@net21

net21 commented Jun 8, 2017

Copy link
Copy Markdown
Author

As you said, the socket object and the queue all will be leaked. It's the new found.

@miguelgrinberg

Copy link
Copy Markdown
Owner

So then this PR is not a complete fix? There's still leaked objects?

@net21

net21 commented Jun 8, 2017

Copy link
Copy Markdown
Author

The server object don't have any chance to del the socket if client don't send the disconnect event in polling mode.

@miguelgrinberg

Copy link
Copy Markdown
Owner

That is incorrect. Any time a message is emitted to a timed out socket, the server will delete it. Is that the situation you are trying to address? I think a better solution would be to be more efficient in detecting these sockets that are abandoned, instead of waiting until they need to be used.

@net21

net21 commented Jun 8, 2017

Copy link
Copy Markdown
Author

I has add some log code, the close method in socket object has been called, but the socket object seems never be deleted in server object.

@miguelgrinberg

Copy link
Copy Markdown
Owner

Do you have a stack trace for the call to close()?

@net21

net21 commented Jun 8, 2017

Copy link
Copy Markdown
Author

File "C:\Python34\lib\site-packages\flask_socketio_init_.py", line 346, in emit
skip_sid=skip_sid, callback=callback, **kwargs)
File "C:\Python34\lib\site-packages\socketio\server.py", line 221, in emit
**kwargs)
File "C:\Python34\lib\site-packages\socketio\base_manager.py", line 135, in emit
self.server._emit_internal(sid, event, data, namespace, id)
File "C:\Python34\lib\site-packages\socketio\server.py", line 396, in _emit_internal
binary=binary))
File "C:\Python34\lib\site-packages\socketio\server.py", line 407, in _send_packet
self.eio.send(sid, encoded_packet, binary=False)
File "C:\Python34\lib\site-packages\engineio\server.py", line 193, in send
socket.send(packet.Packet(packet.MESSAGE, data=data, binary=binary))
File "C:\Python34\lib\site-packages\engineio\socket.py", line 72, in send
self.close(wait=False, abort=True)
File "C:\Python34\lib\site-packages\engineio\socket.py", line 111, in close
traceback.print_stack()

@miguelgrinberg

Copy link
Copy Markdown
Owner

This was fixed in a different way now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants