Netty: 注意不要为java.nio.channels.ClosedChannelException浪费时间
2014-06-26 16:44
1436 查看
服务端Netty在测试时遇到大量java.nio.channels.ClosedChannelException异常。有可能是你的代码有问题,也有可能仅是客户端主动关闭了连接,导致服务端的写失败。
比如,你如果在浏览器里按住F5不停刷新,就会出现大量这样的错误;但用curl/wget高并发地做压测,却并没有这种问题。
如果无聊的用户拼命刷你导致服务端出现大量这种异常怎么办? 一是限流,二是让服务端在写数据之前判断一下channel是否已关闭。
Java代码
if (!channel.isConnected()) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to write any response because the channel is not connected any more. Maybe the client has closed the connection? ");
}
return;
}
比如,你如果在浏览器里按住F5不停刷新,就会出现大量这样的错误;但用curl/wget高并发地做压测,却并没有这种问题。
如果无聊的用户拼命刷你导致服务端出现大量这种异常怎么办? 一是限流,二是让服务端在写数据之前判断一下channel是否已关闭。
Java代码
if (!channel.isConnected()) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to write any response because the channel is not connected any more. Maybe the client has closed the connection? ");
}
return;
}
相关文章推荐
- Netty 中 IOException: Connection reset by peer 与 java.nio.channels.ClosedChannelException: null
- Ignoring exception during shutdown input java.nio.channels.ClosedChannelException
- DUBBO Caused by: java.nio.channels.ClosedChannelException
- spark提交任务java.nio.channels.ClosedChannelException
- dubbo java.nio.channels.ClosedChannelException、com.alibaba.dubbo.remoting.RemotingException: Failed
- storm 报错:java.nio.channels.ClosedChannelException: null
- Kafka异常 java.nio.channels.ClosedChannelException
- java.sql.SQLException: Java exception: ': java.nio.channels.ClosedByInterruptException'.
- 关于hadoop的java.nio.channels.ClosedByInterruptException
- java.nio.channels.FileChannel 使用笔记
- Exception in thread "main" java.lang.AbstractMethodError: weblogic.server.channels.ServerChannelImpl
- Java netty之NioServerSocketChannel
- java.nio.channels.UnresolvedAddressException: null [运行storm-0.9.4集群时]
- java.nio.channels.IllegalBlockingModeException
- java netty之NioSocketChannel
- Caused by: java.nio.channels.NotYetConnectedException: null
- android netty5.0 编译时 java.lang.NoClassDefFoundError: io.netty.channel.nio.NioEventLoopGroup
- java.nio.channels.SocketChannel[connected local=/192.168.10.51:45306 remote=slave1/192.168.10.51:500
- kafka发送消息出现的问题KafKa error java.nio.channels.UnresolvedAddressException
- Storm 执行异常 java.lang.RuntimeException: java.nio.channels.UnresolvedAddressException 问题解决