Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Potential Memory Leak of Websocket Object

we experience a memory leak with the use of Jetty 9.2.21.v20170120 (we are still supporting Java 7). We are using the @Websocket annotation to declare our socket object:

@WebSocket(maxTextMessageSize = 1500)
public class SocketAnnotated {

The socket object is created in a WebSocketCreator, like this:

private class ShipWebSocketCreator implements WebSocketCreator {
    public Object createWebSocket(ServletUpgradeRequest request, ServletUpgradeResponse response) {
        ShipSocketAnnotated shipSocket = new ShipSocketAnnotated(listener, SocketRole.ROLE_SERVER);

 The problem is, that when a connection is established and later closed, the SocketAnnotated object is not gc'ed. It seems that Jetty is internally still holding a reference to it. I have copied the path to the nearest gc root from visualvm to illustrate the problem (a screenshot can be accessed at

this                                          SocketAnnotated
  websocket                                   JettyAnnotatedEventDriver
    incomingHandler                           WebsocketSession
      session                                 WebsocketServerConnection
        _connection                           SslConnection$DecryptedEntpoint
          _decryptedEndPoint                  SslConnection
            _connection                       SslChannelEndPoint
              attachment                      SelectionKeyImpl
                value                         HashMap$Node
                  [0]                         HashMap$Node
                    table                     HashMap
                      tdToKey (JavaFrame)     EPollSelectorImpl

I have also tried this with the latest version of Jetty (9.4.3.v20170317) but the problem still exists (the path the the gc root however looks slightly different).

I would be happy to provide any additional data needed as this is a rather critical problem to us.

Best regards,

Back to the top