Merge remote-tracking branch 'catbref/EPC-fixes' into EPC-fixes

This commit is contained in:
CalDescent 2022-04-19 20:50:32 +01:00
commit 70eaaa9e3b

View File

@ -590,6 +590,7 @@ public class Network {
SelectableChannel socketChannel = nextSelectionKey.channel();
try {
if (nextSelectionKey.isReadable()) {
clearInterestOps(nextSelectionKey, SelectionKey.OP_READ);
Peer peer = getPeerFromChannel((SocketChannel) socketChannel);
@ -617,6 +618,14 @@ public class Network {
clearInterestOps(nextSelectionKey, SelectionKey.OP_ACCEPT);
return new ChannelAcceptTask((ServerSocketChannel) socketChannel);
}
} catch (CancelledKeyException e) {
/*
* Sometimes nextSelectionKey is cancelled / becomes invalid between the isValid() test at line 586
* and later calls to isReadable() / isWritable() / isAcceptable() which themselves call isValid()!
* Those isXXXable() calls could throw CancelledKeyException, so we catch it here and return null.
*/
return null;
}
}
return null;