Uploaded image for project: 'Netty'
  1. Netty
  2. NETTY-424

java.lang.OutOfMemoryError: Direct buffer memory

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.2.2.Final
    • Fix Version/s: None
    • Component/s: Bootstrap
    • Labels:
      None
    • Environment:
      Linux 2.6.18-128.el5xen
      Java HotSpot(TM) 64-Bit Server VM 1.6.0_18-b07

      Description

      • Test:

        for (int i = 0; i < Integer.MAX_VALUE; i ++) {
            ChannelFactory channelFactory = new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
            Bootstrap bootstrap = new ClientBootstrap(channelFactory);
            bootstrap.setPipelineFactory(new ChannelPipelineFactory() { ... });
            ChannelFuture future = bootstrap.connect(serverAddress);
            future.await(); // or future.addListener(new ChannelFutureListener() { ... }); 
            Channel channel = future.getChannel();
            channel.close();
            // FIXME NioClientSocketChannelFactory direct buffer memory leak
            channelFactory.releaseExternalResources(); // or bootstrap.releaseExternalResources();
        }
        

      • Circumvent:
        static NioClientSocketChannelFactory
      • Exception:

        Caused by: java.lang.OutOfMemoryError: Direct buffer memory
        at java.nio.Bits.reserveMemory(Bits.java:633)
        at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
        at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
        at org.jboss.netty.channel.socket.nio.SocketSendBufferPool$Preallocation.<init>(SocketSendBufferPool.java:159)
        at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.<init>(SocketSendBufferPool.java:46)
        at org.jboss.netty.channel.socket.nio.NioWorker.<init>(NioWorker.java:84)
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.<init>(NioClientSocketPipelineSink.java:74)
        at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.<init>(NioClientSocketChannelFactory.java:135)

        Gliffy Diagrams

          Activity

          Hide
          trustin Trustin Lee added a comment -

          ChannelFactories are never meant to be created many times. JVM is poor at managing direct buffers, so there's no way to fix this problem without using JNI. One possible workaround would be call System.gc() explicitly, but I'm not sure it's a reliable workaround.

          Show
          trustin Trustin Lee added a comment - ChannelFactories are never meant to be created many times. JVM is poor at managing direct buffers, so there's no way to fix this problem without using JNI. One possible workaround would be call System.gc() explicitly, but I'm not sure it's a reliable workaround.
          Hide
          minisaw mini saw added a comment -

          we are facing the same problem, and request to have it configurable whether NETTY uses direct buffers or heap buffers.

          Show
          minisaw mini saw added a comment - we are facing the same problem, and request to have it configurable whether NETTY uses direct buffers or heap buffers.
          Hide
          trustin Trustin Lee added a comment -

          I agree it should be more configurable. I'm thinking of providing some buffer pools and let user specify it. Please stay tuned.

          Show
          trustin Trustin Lee added a comment - I agree it should be more configurable. I'm thinking of providing some buffer pools and let user specify it. Please stay tuned.
          Hide
          scampbell3 Stan Campbell added a comment -

          Doesn't look like there's been any progress on this? Is there a known workaround?

          Show
          scampbell3 Stan Campbell added a comment - Doesn't look like there's been any progress on this? Is there a known workaround?

            People

            • Assignee:
              trustin Trustin Lee
              Reporter:
              liangfei0201 liangfei liang
            • Votes:
              4 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:

                Development