3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-12 10:15:49 +00:00

EPC-fixes: catch CancelledKeyExceptions thrown in short window between nextSelectionKey.isValid() and nextSelectionKey.isXXXable() calls

This commit is contained in:
catbref 2022-04-18 14:33:05 +01:00
parent 68412b49a1
commit 3e622f7185

View File

@ -590,6 +590,7 @@ public class Network {
SelectableChannel socketChannel = nextSelectionKey.channel(); SelectableChannel socketChannel = nextSelectionKey.channel();
try {
if (nextSelectionKey.isReadable()) { if (nextSelectionKey.isReadable()) {
clearInterestOps(nextSelectionKey, SelectionKey.OP_READ); clearInterestOps(nextSelectionKey, SelectionKey.OP_READ);
Peer peer = getPeerFromChannel((SocketChannel) socketChannel); Peer peer = getPeerFromChannel((SocketChannel) socketChannel);
@ -617,6 +618,14 @@ public class Network {
clearInterestOps(nextSelectionKey, SelectionKey.OP_ACCEPT); clearInterestOps(nextSelectionKey, SelectionKey.OP_ACCEPT);
return new ChannelAcceptTask((ServerSocketChannel) socketChannel); 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; return null;