GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java.lang.OutOfMemoryError: unable to create new native thread · Issue #7520 · netty/netty

java.lang.OutOfMemoryError: unable to create new native thread #7520

New issue
Copy link
New issue
Copy link
Closed
Closed
java.lang.OutOfMemoryError: unable to create new native thread#7520
Copy link

Description

@talonx
talonx
opened on Dec 18, 2017
Issue body actions

Expected behavior

No out of memory error

Actual behavior

Out of memory error after the app runs for a couple of days

WARNING: Runnable threw exception in ChannelExecutor
java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:717)
        at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957)
        at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1606)
        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:334)
        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533)
        at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:622)
        at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:668)
        at io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:282)
        at io.grpc.internal.ManagedChannelImpl$LbHelperImpl$3.run(ManagedChannelImpl.java:696)
        at io.grpc.internal.ChannelExecutor.drain(ChannelExecutor.java:72)
        at io.grpc.internal.InternalSubchannel$TransportListener.transportReady(InternalSubchannel.java:449)
        at io.grpc.netty.ClientTransportLifecycleManager.notifyReady(ClientTransportLifecycleManager.java:43)
        at io.grpc.netty.NettyClientHandler$FrameListener.onSettingsRead(NettyClientHandler.java:637)
        at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:423)
        at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$PrefaceFrameListener.onSettingsRead(DefaultHttp2ConnectionDecoder.java:635)
        at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onSettingsRead(Http2InboundFrameLogger.java:93)
        at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readSettingsFrame(DefaultHttp2FrameReader.java:542)
        at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:263)
        at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)
        at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41)
        at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder.decodeFrame(DefaultHttp2ConnectionDecoder.java:118)
        at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:354)
        at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:225)
        at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:414)
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1336)
        at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1127)
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1162)
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1342)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:934)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)

Steps to reproduce

The code talks to Google PubSub and Bigtable APIs via GRPC, and netty is used underneath. After a while we observe that heap memory is not decreasing beyond a certain point even after GC. Analysis of a heap dump reveals a lot of objects (image below)
heap-dump-analysis

The app runs inside Tomcat (8.0.32-1ubuntu1.4)

Minimal yet complete reproducer code (or URL to code)

Difficult to give a standalone piece of the code since we are not sure which API calls lead to this.

Netty version

There are two versions - 4.1.14Final as a dependency for Google PubSub, and 4.1.8Final as a shaded jar for a Google Bigtable/Hbase dependency in the same application.

JVM version (e.g. java -version)

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

OS version (e.g. uname -a)

Linux 4.10.0-40-generic #44~16.04.1-Ubuntu SMP Thu Nov 9 15:37:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

Activity

  1. normanmaurer commented on Dec 18, 2017

    @normanmaurer
    normanmaurer
    on Dec 18, 2017
    Member
    More actions

    @talonx could you share the heap dump ? from the screenshot it seems you may need to size the caches differently but hard to tell without navigate through the heap-dump

  2. talonx commented on Dec 18, 2017

    @talonx
    talonx
    on Dec 18, 2017
    Author
    More actions

    @normanmaurer I've shared the heap dump to your Github profile email address, since I cannot share it publicly for security reasons.

  3. normanmaurer commented on Dec 18, 2017

    @normanmaurer
    normanmaurer
    on Dec 18, 2017
    Member
    More actions

    @talonx thanks will check soon.

  4. Scottmitch commented on Dec 19, 2017

    @Scottmitch
    Scottmitch
    on Dec 19, 2017
    Member
    More actions

    /cc @ejona86 @carl-mastrangelo

  5. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx do you "redeploy" the app via tomcat ?

  6. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    @normanmaurer No, we restart on every new deployment. The leak shows up without any redeploys.

  7. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx how many "IO threads" you are using ?

  8. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx and also how many "active" threads you have in your app at all.

  9. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    @normanmaurer We don't use Netty APIs directly - they are used by GRPC/Bigtable & PubSub APIs. Other than threads created by these libraries, we have very few threads that we create on our own - maybe less than 10 at any given point in time.

  10. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx and how many threads all together ? Should be easy to check via a thread-dump for example

  11. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    I just checked - the currently running VM has 13093 threads.

  12. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    13093 threads this is way to much... I suspect you not shutdown something correctly. As each thread that will allocate buffers has a thread local cache its no wonder this blows up.

  13. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    I don't directly create threads that call Netty - but I'll check my code again for other threads (or thread pools) that are not being shutdown.

  14. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx maybe you bootstrap GRPC multiple times and not shut it down etc... Not sure but this does not sound right.. I mean you could also disable the cache all together but I think the root cause is something you should fix here.

  15. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    @normanmaurer I'll check that. Disabling the cache might increase the time span before the OOM happens but it would still hit other limits if the thread count keeps going up.

  16. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx yep... let me close the issue but please report back what the problem was at the end... Like I said I suspect you may just not correctly use GRPC and so bootstrap a lot of instances but never close these.

  17. normanmaurer
    closed this as completedon Dec 19, 2017
  18. talonx commented on Dec 19, 2017

    @talonx
    talonx
    on Dec 19, 2017
    Author
    More actions

    Thanks. I think I have narrowed it down to the Google PubSub library - which is triggering creation of the threads, will need some more investigation.

  19. normanmaurer commented on Dec 19, 2017

    @normanmaurer
    normanmaurer
    on Dec 19, 2017
    Member
    More actions

    @talonx thanks a lot...

  20. talonx commented on Dec 21, 2017

    @talonx
    talonx
    on Dec 21, 2017
    Author
    More actions

    @normanmaurer This is resolved - as you rightly suspected some PubSub resources were not being closed properly in our code. It took a while to track this down as the thread pools/threads names in the thread dump don't indicate what they were created for, but we are handling that now by supplying our own ThreadFactory to PubSub. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.