INT-2333 Work Around for MAC OSX JVM Bug

Selector.select() throws CancelledKeyException when selecting
on a closed socket.

http://java.net/jira/browse/MACOSX_PORT-526

Work around is to catch the exception and continue.
This commit is contained in:
Gary Russell
2011-12-22 15:18:59 -05:00
committed by Mark Fisher
parent bc09b0617c
commit 49c52353cd

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@@ -123,7 +124,14 @@ public class TcpNioClientConnectionFactory extends
while (this.isActive()) {
SocketChannel newChannel;
int soTimeout = this.getSoTimeout();
int selectionCount = selector.select(soTimeout < 0 ? 0 : soTimeout);
int selectionCount = 0;
try {
selectionCount = selector.select(soTimeout < 0 ? 0 : soTimeout);
} catch (CancelledKeyException cke) {
if (logger.isDebugEnabled()) {
logger.debug("CancelledKeyException during Selector.select()");
}
}
while ((newChannel = newChannels.poll()) != null) {
try {
newChannel.register(this.selector, SelectionKey.OP_READ, connections.get(newChannel));