首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >netty: WARNING:触发了exceptionCaught()事件,它到达了管道的尾部

netty: WARNING:触发了exceptionCaught()事件,它到达了管道的尾部
EN

Stack Overflow用户
提问于 2017-03-16 20:52:05
回答 1查看 4.5K关注 0票数 1

我为我的客户端编写了服务来处理多个客户端,它工作得很好,但是最近几天客户端的负载增加了,现在服务器代码产生了异常,我不能理解它是怎么回事。

我的代码是:

代码语言:javascript
复制
    public void run() throws Exception {

    //System.setProperty("org.jboss.netty.epollBugWorkaround", "true");
    EventLoopGroup bossPool = new NioEventLoopGroup(BOSS_THREADS);
    EventLoopGroup workerPool = new NioEventLoopGroup(MAX_WORKER_THREADS);

    try {

        ServerBootstrap boot = new ServerBootstrap();
        boot.group(bossPool, workerPool);
        boot.channel(NioServerSocketChannel.class);
        boot.childHandler(new Pipeline());
        boot.option(ChannelOption.TCP_NODELAY, true);
        boot.option(ChannelOption.SO_KEEPALIVE, true);
        boot.option(ChannelOption.SO_REUSEADDR, true);
        boot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 6000);
        boot.option(ChannelOption.SO_TIMEOUT, 6);
        boot.option(ChannelOption.SO_BACKLOG, 2048);

        //System.out.println("Server started listening at port : " + port);
        boot.bind(port).sync().channel().closeFuture().sync();

    } catch (InterruptedException e) {
    } finally {
        workerPool.shutdownGracefully();
        bossPool.shutdownGracefully();
    }
}

管道代码为:

代码语言:javascript
复制
    public class Pipeline extends ChannelInitializer<Channel> {
    @Override
    protected void initChannel(Channel ch) throws Exception {
        // ch.pipeline().addLast("joiner", new JoinRequest());
        ch.pipeline().addLast("decoder", new ByteArrayDecoder());
        ch.pipeline().addLast("encoder", new StringEncoder());
        ch.pipeline().addLast("myHelper", new RequestHandler());
       }
    }

这是我每天得到的详细的错误日志:

代码语言:javascript
复制
1006465:54:21:10-16-03-2017Mar 16, 2017 10:21:54 AM         io.netty.channel.DefaultChannelPipeline$TailContext exceptionCaught
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: Too many open files
    at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
    at io.netty.channel.socket.nio.NioServerSocketChannel.doReadMessages(NioServerSocketChannel.java:135)
    at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:69)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:514)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:471)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:385)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:351)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412)
    at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280)
    at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877)
    at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706)
    at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661)
    at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126)

com.idea.builders.RequestHandler oprationSelector
SEVERE: null
java.io.FileNotFoundException: config.dat (Too many open files)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at java.io.FileReader.<init>(FileReader.java:58)
    at com.idea.builders.RequestHandler.oprationSelector(RequestHandler.java:175)
    at com.idea.builders.RequestHandler.messageReceived(RequestHandler.java:97)
    at com.idea.builders.RequestHandler.messageReceived(RequestHandler.java:35)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:84)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:153)
    at io.netty.channel.PausableChannelEventExecutor.invokeChannelRead(PausableChannelEventExecutor.java:86)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:389)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:84)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelRead(DefaultChannelHandlerInvoker.java:153)
    at io.netty.channel.PausableChannelEventExecutor.invokeChannelRead(PausableChannelEventExecutor.java:86)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:389)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:956)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:127)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:514)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:471)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:385)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:351)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412)
    at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280)
    at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877)
    at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706)
    at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661)
    at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126)

Mar 16, 2017 10:21:54 AM com.idea.builders.RequestHandler oprationSelector
SEVERE: null
java.io.FileNotFoundException: config.dat (Too many open files)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at java.io.FileReader.<init>(FileReader.java:58)
    at com.idea.builders.RequestHandler.oprationSelector(RequestHandler.java:175)
    at com.idea.builders.RequestHandler.messageReceived(RequestHandler.java:97)
    at com.idea.builders.RequestHandler.messageReceived(RequestHandler.java:35)

我应该怎么做才能每天重新启动我的服务器?

EN

回答 1

Stack Overflow用户

发布于 2017-04-02 18:35:18

您应该在其中一个处理程序中重写exceptionCaught方法。

该消息表示netty caugth异常,但您没有在任何处理程序中处理它。异常只会到达最后一个管道处理程序并消失。您可能应该在请求处理程序中处理它。

是的,在你处理完文件后,关闭所有的流。此外,您还应该在异常或未注册事件时释放套接字和其他资源。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42834652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档