【发布时间】:2014-09-17 10:36:38
【问题描述】:
最近我们使用“-Dorg.jboss.netty.epollBugWorkaround=true”标志来启用 java 1.6 选择器错误的解决方法。 http://netty.io/news/2012/09/06/3-5-7-final.html
我们认为 netty 3.5.10 中的解决方法存在错误。
当通道未连接时,它会遍历键并取消它们。
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.Boss.run()
for (SelectionKey key: selector.keys()) {
SelectableChannel ch = key.channel();
try {
if (ch instanceof SocketChannel && !((SocketChannel) ch).isConnected()) {
notConnected = true;
// cancel the key just to be on the safe side
key.cancel();
}
} catch (CancelledKeyException e) {
}
}
在这种情况下,当通道未连接时,可能会取消通道连接失败事件。
我们发现它是因为我们的代码在没有超时的情况下等待连接事件成功/失败(使用“ChannelFutureListener”)并且没有返回此事件。 我们的代码依赖于总是返回连接事件,无论是成功还是失败。
您如何看待以下修复?
if (! key.isConnectable() ) {
key.cancel();
}
【问题讨论】: