title: Potential memory leak of websocket sessions in jetty (9.4.15)
body: <p>I have a service that accept and create several websocket sessions back and forth (they are closed and then reopened etc). For closing the websocket sessions, I am calling the <code>close</code> method the <strong>webSocketSession</strong> object of spring, which is tied inside, I guess, to jetty's own <strong>WebSocketSession</strong> object.</p>
  
  <p>My service runs with spring boot (1.5.20) with an embedded jetty server (9.4.15), and is using G1 GC with default parameters (perhaps will be fine tuned later on)</p>
  
  <p>lately, it seems that this service has some memory leak which I am trying to investigate.
  I have taken a heap dump after verifying from the application POV that I have no open sessions from my side, and after manually "forcing" GC (using JConsole). </p>
  
  <p>The heap dump was taken using JConsole with <strong>live=true</strong> parameter, so I am most certainly sure that I have a dump after GC had performed all available cleanup on it.</p>
  
  <p>I have analyzed the dump using Eclipse MAT, and found out that I have ~8K
  <strong>WebSocketSession</strong> objects that are kept alive. This metric is somehow proportional to an applicative metric I have showing that my service dealt with so far with ~8K connections (8K of incoming WS connections and 8K of outgoing WS connections where I am using jetty as a WS client).</p>
  
  <p>I have analyzed the path to GC roots to one of these objects, and found that it is being held, among others, by some of Jetty threads (qtp-XXX threads) and by some schedulers (see set of images below)
  <a href="https://i.stack.imgur.com/matgx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/matgx.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/kZoJA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZoJA.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/TV9J0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TV9J0.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/T0JP3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T0JP3.png" alt="enter image description here"></a>
  My questions:</p>
  
  <ol>
  <li>Does any one came across such behavior of jetty with problem releasing websockets resources over time ?</li>
  <li>I see some scheduler threads that also holds the websocket sessions. Does any one knows if these are internals of jetty ? or are they contributed from spring boot layer ? or something else ?</li>
  <li>Could it be that Jetty holds all sessions internally (even the ones that were closed) and only periodically releasing them ? (or some sort of mechanism that would explain how I have these 8K supposedly closed sessions live and active ?)</li>
  </ol>