mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-13 10:57:56 +00:00
Handle getting a null from getNewParser gracefully
This commit is contained in:
@@ -23,6 +23,7 @@ import java.nio.channels.spi.SelectorProvider;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.util.concurrent.AbstractExecutionThreadService;
|
import com.google.common.util.concurrent.AbstractExecutionThreadService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -45,9 +46,15 @@ public class NioServer extends AbstractExecutionThreadService {
|
|||||||
SocketChannel newChannel = sc.accept();
|
SocketChannel newChannel = sc.accept();
|
||||||
newChannel.configureBlocking(false);
|
newChannel.configureBlocking(false);
|
||||||
SelectionKey newKey = newChannel.register(selector, SelectionKey.OP_READ);
|
SelectionKey newKey = newChannel.register(selector, SelectionKey.OP_READ);
|
||||||
ConnectionHandler handler = new ConnectionHandler(parserFactory, newKey);
|
try {
|
||||||
newKey.attach(handler);
|
ConnectionHandler handler = new ConnectionHandler(parserFactory, newKey);
|
||||||
handler.parser.connectionOpened();
|
newKey.attach(handler);
|
||||||
|
handler.parser.connectionOpened();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// This can happen if ConnectionHandler's call to get a new handler returned null
|
||||||
|
log.error("Error handling new connection", Throwables.getRootCause(e).getMessage());
|
||||||
|
newKey.channel().close();
|
||||||
|
}
|
||||||
} else { // Got a closing channel or a channel to a client connection
|
} else { // Got a closing channel or a channel to a client connection
|
||||||
ConnectionHandler.handleKey(key);
|
ConnectionHandler.handleKey(key);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user