<div dir="ltr"><div>I have undertow embedded into my application and for the most part its working great, but unfortunately I&#39;ve found a memory leak.  The application its self creates an Undertow server using SSL and then adds servlets and filters.  There are no custom handlers.</div><div><br></div><div>Throughout the logs I get the following NPEs:</div><div><br></div><div><div>2016-01-14 09:50:04,681][XNIO-2 task-28] ERROR request - UT005071: Undertow request failed HttpServerExchange{ GET /wp-content/themes/Nexus/style.css request {Accept=[text/css, */*], Connection=[Keep-Alive], Accept-Language=[en-US,en;q=0.5], Accept-Encoding=[gzip, deflate], Cookie=[nowwwsession=eyJpdiI6Ik5hV0xCWWR5VExzUEEzRTBVNUFKUkFcdTAwM2RcdTAwM2QiLCJlbmNyeXB0ZWRSZXF1ZXN0IjoiS2t0TENaVGZFb1NWNjlyVXB4aUxuQ2RHRmlTZzVDWm0veTFXLytXWlBQMEhpMDZKK3FaQWpQYnBGY0RnMW15RCJ9; nvers-prod-session=eyJpdiI6Ikd2Wk5oTDVGbjdSTElGejlQSzFsalFcdTAwM2RcdTAwM2QiLCJlbmNyeXB0ZWRSZXF1ZXN0IjoiN2VldzBiT1lIWkZNaVgwTzV5b2tUSVNnaWwzTC9tRHpmeEdDOFZiQzh2a1RZN29ScElqbHFyZys3dmZMWUNhRSJ9], Referer=[<a href="https://www.nvers.org/the-team/">https://www.nvers.org/the-team/</a>], User-Agent=[Mozilla/5.0 (Windows NT 10.0; Trident/7.0; MALC; rv:11.0) like Gecko], Host=[<a href="http://www.nvers.org">www.nvers.org</a>]} response {Connection=[close], Last-Modified=[Thu, 26 Mar 2015 18:45:16 GMT], Server=[Apache/2.2.15 (CentOS)], Content-Type=[text/css], Content-Language=[en-US], Accept-Ranges=[bytes], Date=[Thu, 14 Jan 2016 14:37:10 GMT]}}</div><div>java.lang.NullPointerException</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.protocol.http.HttpResponseConduit.flush(HttpResponseConduit.java:713)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.conduits.FinishableStreamSinkConduit.flush(FinishableStreamSinkConduit.java:83)</div><div><span class="" style="white-space:pre">        </span>at org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119)</div><div><span class="" style="white-space:pre">        </span>at org.xnio.channels.Channels.flushBlocking(Channels.java:63)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:609)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter(HttpServletResponseImpl.java:476)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:560)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:331)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)</div><div><span class="" style="white-space:pre">        </span>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)</div><div><span class="" style="white-space:pre">        </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)</div><div><span class="" style="white-space:pre">        </span>at java.lang.Thread.run(Thread.java:745)</div></div><div><br></div><div><br></div><div>Also, I see the following in System.out:</div><div><div>Exception in thread &quot;XNIO-2 task-18&quot; java.lang.NullPointerException</div><div>          at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:605)</div><div>          at io.undertow.conduits.ChunkedStreamSinkConduit.flush(ChunkedStreamSinkConduit.java:267)</div><div>          at org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162)</div><div>          at io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119)</div><div>          at io.undertow.server.HttpServerExchange.closeAndFlushResponse(HttpServerExchange.java:1652)</div><div>          at io.undertow.server.HttpServerExchange.endExchange(HttpServerExchange.java:1630)</div><div>          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:226)</div><div>          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)</div><div>          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)</div><div>          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)</div><div>          at java.lang.Thread.run(Thread.java:745)</div></div><div><br></div><div>After taking a heap dump and analyzing, I&#39;m finding that a single thread is holding all the objects:</div><div>







<p class=""><span class="">The thread <b>org.xnio.nio.WorkerThread @ 0xc48cac70 XNIO-2 I/O-4</b> keeps local variables with total size <b>578,543,888 (95.77%)</b> bytes.</span></p><p class=""><span class="">








</span></p><p class=""><span class="">The memory is accumulated in one instance of <b>&quot;java.lang.Object[]&quot;</b> loaded by <b>&quot;&lt;system class loader&gt;&quot;</b>.</span></p><p class=""><span class="">XNIO-2 I/O-4</span></p>
<p class=""><span class="">  at sun.security.ssl.SSLEngineImpl.unwrap(Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;II)Ljavax/net/ssl/SSLEngineResult; (SSLEngineImpl.java:781)</span></p>
<p class=""><span class="">  at io.undertow.protocols.ssl.SslConduit.doUnwrap([Ljava/nio/ByteBuffer;II)J (SslConduit.java:682)</span></p>
<p class=""><span class="">  at io.undertow.protocols.ssl.SslConduit.read(Ljava/nio/ByteBuffer;)I (SslConduit.java:525)</span></p>
<p class=""><span class="">  at org.xnio.conduits.ConduitStreamSourceChannel.read(Ljava/nio/ByteBuffer;)I (ConduitStreamSourceChannel.java:127)</span></p>
<p class=""><span class="">  at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(Lorg/xnio/conduits/ConduitStreamSourceChannel;)V (HttpReadListener.java:149)</span></p>
<p class=""><span class="">  at io.undertow.server.protocol.http.HttpReadListener.handleEvent(Lorg/xnio/conduits/ConduitStreamSourceChannel;)V (HttpReadListener.java:127)</span></p>
<p class=""><span class="">  at io.undertow.server.protocol.http.HttpReadListener.handleEvent(Ljava/nio/channels/Channel;)V (HttpReadListener.java:56)</span></p>
<p class=""><span class="">  at org.xnio.ChannelListeners.invokeChannelListener(Ljava/nio/channels/Channel;Lorg/xnio/ChannelListener;)Z (ChannelListeners.java:92)</span></p>
<p class=""><span class="">  at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady()V (ReadReadyHandler.java:66)</span></p>
<p class=""><span class="">  at io.undertow.protocols.ssl.SslConduit$SslReadReadyHandler.readReady()V (SslConduit.java:1054)</span></p>
<p class=""><span class="">  at io.undertow.protocols.ssl.SslConduit$1.run()V (SslConduit.java:225)</span></p>
<p class=""><span class="">  at org.xnio.nio.WorkerThread.safeRun(Ljava/lang/Runnable;)V (WorkerThread.java:580)</span></p>
<p class=""><span class="">  at org.xnio.nio.WorkerThread.run()V (WorkerThread.java:464)</span></p><p class=""><br></p></div><div>Any help would be appreciated.  We didn&#39;t have any memory leak issues with Jetty which is what we used prior so I don&#39;t think its an issue with our internal code triggering this.</div><div><br></div><div>Thanks</div><br clear="all"><div><div class="gmail_signature">Marc Boorshtein<div>CTO Tremolo Security</div><div><a href="mailto:marc.boorshtein@tremolosecurity.com" target="_blank">marc.boorshtein@tremolosecurity.com</a></div><div><a href="mailto:marc.boorshtein@tremolosecurity.com" target="_blank"></a><br></div></div></div>
</div>