Skip to content

Memory leak in WebSocketImpl.outQueue #773

@martin-g

Description

@martin-g

Hi,

This is not a bug report or feature request but actually I'd like to ask for help debugging a possible memory leak.

In the following screenshot you can see that ~51% of the used heap is kept by WebSocketWorker and WebSocketImpl.

51-percents-in-websocketserver

And here we see that actually WebSocketImpl#outQueue (with hashcode 0x7127e8b30) is the one keeping the memory.
outqueue

Its size is 25320:
queue-size-25320

Debugging the code I've seen that outQueue is populated when I use org.java_websocket.WebSocket#send(java.lang.String) method. At that time there is a check whether the connection is still opened and WebsocketNotConnectedException is being thrown in case it is not. Then org.java_websocket.WebSocketImpl#write(java.nio.ByteBuffer) is called where there the buf is just put into outQueue.
Later in the run loop of org.java_websocket.server.WebSocketServer#run() the outQueue must be drained and actually sent to the client. In case of an error an IOException is thrown and org.java_websocket.server.WebSocketServer#onClose(WebSocket, int, String, boolean) callback is called.

One thing that I notice is that neither org.java_websocket.server.WebSocketServer#handleIOException() nor org.java_websocket.WebSocketImpl#closeConnection(int, java.lang.String, boolean) clear the contents of inQueue and outQueue. But I am not sure whether this is the reason for the huge out queues I have in the heap dump.

Do you have an idea what could be the problem and what I could do to debug more ?

I use version 1.3.8. I see that 1.3.9 is released and I will upgrade to it but I do not see anything that might fix it in the changelog.

For the heap analysis I use Eclipse Memory Analyzer (v 1.8.0).

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions