Merge pull request #555 from netty/nio_100percent_cpu_fix

Partial fix for 100% cpu usage when using nio client. See #535
This commit is contained in:
Norman Maurer 2012-08-23 23:34:04 -07:00
commit 573fbfa518

View File

@ -362,8 +362,16 @@ class NioClientSocketPipelineSink extends AbstractNioChannelSink {
continue;
}
if (k.isConnectable()) {
connect(k);
try {
if (k.isConnectable()) {
connect(k);
}
} catch (Throwable t) {
NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment();
ch.connectFuture.setFailure(t);
fireExceptionCaught(ch, t);
k.cancel(); // Some JDK implementations run into an infinite loop without this.
ch.worker.close(ch, succeededFuture(ch));
}
}
}
@ -398,18 +406,11 @@ class NioClientSocketPipelineSink extends AbstractNioChannelSink {
}
}
private void connect(SelectionKey k) {
private void connect(SelectionKey k) throws IOException {
NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment();
try {
if (ch.channel.finishConnect()) {
k.cancel();
ch.worker.register(ch, ch.connectFuture);
}
} catch (Throwable t) {
ch.connectFuture.setFailure(t);
fireExceptionCaught(ch, t);
k.cancel(); // Some JDK implementations run into an infinite loop without this.
ch.worker.close(ch, succeededFuture(ch));
if (ch.channel.finishConnect()) {
k.cancel();
ch.worker.register(ch, ch.connectFuture);
}
}