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 #7520DescriptionExpected 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)

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" Activitynormanmaurer commented on Dec 18, 2017 @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 talonx commented on Dec 18, 2017 @normanmaurer I've shared the heap dump to your Github profile email address, since I cannot share it publicly for security reasons. normanmaurer commented on Dec 18, 2017 Scottmitch commented on Dec 19, 2017 normanmaurer commented on Dec 19, 2017 @talonx do you "redeploy" the app via tomcat ? talonx commented on Dec 19, 2017 @normanmaurer No, we restart on every new deployment. The leak shows up without any redeploys. normanmaurer commented on Dec 19, 2017 @talonx how many "IO threads" you are using ? normanmaurer commented on Dec 19, 2017 @talonx and also how many "active" threads you have in your app at all. talonx commented on Dec 19, 2017 @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. normanmaurer commented on Dec 19, 2017 @talonx and how many threads all together ? Should be easy to check via a thread-dump for example talonx commented on Dec 19, 2017 I just checked - the currently running VM has 13093 threads. normanmaurer commented on Dec 19, 2017 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.
talonx commented on Dec 19, 2017 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. normanmaurer commented on Dec 19, 2017 @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. talonx commented on Dec 19, 2017 @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. normanmaurer commented on Dec 19, 2017 @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. talonx commented on Dec 19, 2017 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. normanmaurer commented on Dec 19, 2017 talonx commented on Dec 21, 2017 @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.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|