Browse Source

EPC-fixed: avoiding some CancelledKeyExceptions

EPC-fixes
catbref 3 years ago
parent
commit
8e09567221
  1. 8
      src/main/java/org/qortal/network/Network.java

8
src/main/java/org/qortal/network/Network.java

@ -582,6 +582,10 @@ public class Network {
final SelectionKey nextSelectionKey = channelIterator.next(); final SelectionKey nextSelectionKey = channelIterator.next();
channelIterator.remove(); channelIterator.remove();
// Just in case underlying socket channel already closed elsewhere, etc.
if (!nextSelectionKey.isValid())
return null;
LOGGER.trace("Thread {}, nextSelectionKey {}", Thread.currentThread().getId(), nextSelectionKey); LOGGER.trace("Thread {}, nextSelectionKey {}", Thread.currentThread().getId(), nextSelectionKey);
SelectableChannel socketChannel = nextSelectionKey.channel(); SelectableChannel socketChannel = nextSelectionKey.channel();
@ -844,7 +848,9 @@ public class Network {
this.removeConnectedPeer(peer); this.removeConnectedPeer(peer);
this.channelsPendingWrite.remove(peer.getSocketChannel()); this.channelsPendingWrite.remove(peer.getSocketChannel());
if (getImmutableConnectedPeers().size() < maxPeers - 1 && (serverSelectionKey.interestOps() & SelectionKey.OP_ACCEPT) == 0) { if (getImmutableConnectedPeers().size() < maxPeers - 1
&& serverSelectionKey.isValid()
&& (serverSelectionKey.interestOps() & SelectionKey.OP_ACCEPT) == 0) {
try { try {
LOGGER.debug("Re-enabling accepting incoming connections because the server is not longer full"); LOGGER.debug("Re-enabling accepting incoming connections because the server is not longer full");
setInterestOps(serverSelectionKey, SelectionKey.OP_ACCEPT); setInterestOps(serverSelectionKey, SelectionKey.OP_ACCEPT);

Loading…
Cancel
Save