Details
Description
OutOfMemoryError occurs every once in a while, following by a Denial of Service (that is, the Jetty server stops responding until it is restarted).
:WARN: handle failed
java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:99)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
at sun.nio.ch.IOUtil.write(IOUtil.java:134)
at sun.nio.ch.SocketChannelImpl.write0(SocketChannelImpl.java:331)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:354)
at java.nio.channels.SocketChannel.write(SocketChannel.java:360)
at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:238)
at org.mortbay.jetty.nio.HttpChannelEndPoint.flush(HttpChannelEndPoint.java:141)
at org.mortbay.jetty.HttpGenerator.flushBuffers(HttpGenerator.java:754)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:321)
at org.mortbay.jetty.nio.HttpChannelEndPoint.run(HttpChannelEndPoint.java:270)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:99)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
at sun.nio.ch.IOUtil.write(IOUtil.java:134)
at sun.nio.ch.SocketChannelImpl.write0(SocketChannelImpl.java:331)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:354)
at java.nio.channels.SocketChannel.write(SocketChannel.java:360)
at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:238)
at org.mortbay.jetty.nio.HttpChannelEndPoint.flush(HttpChannelEndPoint.java:141)
at org.mortbay.jetty.HttpGenerator.flushBuffers(HttpGenerator.java:754)
at org.mortbay.jetty.HttpConnection.flushResponse(HttpConnection.java:480)
at org.mortbay.jetty.HttpConnection$Output.close(HttpConnection.java:711)
I suspect this is an issue described in SDN Bug 4797189:
http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4797189
If so, solutions would be to provide an option not to use direct buffers (too much trouble with them, and little to no performance improvement, so, for example, Berkley DB-JE made them an option, which is by default turned off).
Another solution would be to have a pool of direct memory buffers. Summary: you can't just allocate direct memory buffers, becouse the GC will "forget" about them, causing OOM. But with small memory buffers the pool would be ok.