Netty: how to fix this java.lang.IllegalStateException:failed to create a child event loop err

Created on 22 Sep 2017  路  6Comments  路  Source: netty/netty

java.lang.IllegalStateException:failed to create a child event loop
2 io.netty.util.concurrent.MultithreadEventExecutorGroup.(SourceFile:99)
3 ......
4 Caused by:
5 java.io.IOException:Too many open files
6 sun.nio.ch.IOUtil.makePipe(Native Method)
7 sun.nio.ch.PollSelectorImpl.(PollSelectorImpl.java:57)
8 sun.nio.ch.PollSelectorProvider.openSelector(PollSelectorProvider.java:36)
9 io.netty.channel.nio.NioEventLoop.openSelector(SourceFile:124)
10 io.netty.channel.nio.NioEventLoop.(SourceFile:118)
11 io.netty.channel.nio.NioEventLoopGroup.newChild(SourceFile:140)
12 io.netty.channel.nio.NioEventLoopGroup.newChild(SourceFile:31)
13 io.netty.util.concurrent.MultithreadEventExecutorGroup.(SourceFile:95)
14 io.netty.util.concurrent.MultithreadEventExecutorGroup.(SourceFile:68)
15 io.netty.channel.MultithreadEventLoopGroup.(SourceFile:49)
16 io.netty.channel.nio.NioEventLoopGroup.(SourceFile:100)
17 io.netty.channel.nio.NioEventLoopGroup.(SourceFile:71)
18 io.netty.channel.nio.NioEventLoopGroup.(SourceFile:56)
19 io.netty.channel.nio.NioEventLoopGroup.(SourceFile:41)
20 com.ninexiu.sixninexiu.common.util.m.(SourceFile:71)
21 com.ninexiu.sixninexiu.common.util.m.a(SourceFile:140)
22 com.ninexiu.sixninexiu.d.bm$3.run(SourceFile:1225)
23 android.os.Handler.handleCallback(Handler.java:761)
24 android.os.Handler.dispatchMessage(Handler.java:98)
25 android.os.Looper.loop(Looper.java:156)
26 android.app.ActivityThread.main(ActivityThread.java:6577)
27 java.lang.reflect.Method.invoke(Native Method)
28 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
29 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

I use this version: netty-all-5.0.0.Alpha2.jar in Android app .
this is my init code
group = new NioEventLoopGroup(); bootstrap = new Bootstrap(); bootstrap.channel(NioSocketChannel.class); bootstrap.option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_BACKLOG, 10000) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_LINGER, 0) .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_RCVBUF, 8192) .option(ChannelOption.SO_SNDBUF, 8192); bootstrap.group(group); bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline channelPipeline = ch.pipeline(); channelPipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, -2, 2)); channelPipeline.addLast(new MessageBinaryDecoder()); channelPipeline.addLast(new MessageEncoder()); channelPipeline.addLast(new ChatClientHandler(mHandler)); } });

and this is my disconnect code
public void disconnect() { try { if(ch!=null){ ch.disconnect(); ch.close(); ch = null; } } catch (Exception e) { e.printStackTrace(); } }

I don't understand why cause this err.

Most helpful comment

How can this be fixed on a mac?

All 6 comments

Maybe you have opened too many connecitons. try lsof -n | grep pid to see if your app has too many open file, and increase the limitation by ulimit -n

5.0 has been abandoned. Please use the latest 4.1 release.

You will need to increase your open file limit if you already closing the connections probably.

yeah , limit create instance fix it .I will update to 4.1 release.

You can see "Too many open files" in exception trace which is caused when you have open file count more than allowed open file count. This happens either because you have FD leak or you need to increase FD limit which can be done by updating file /etc/security/limits.conf

How can this be fixed on a mac?

Was this page helpful?
0 / 5 - 0 ratings