3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-16 04:05:50 +00:00

nonetty: Print fewer stack traces on errors. Handle failure of initial connect call.

This commit is contained in:
Mike Hearn 2013-11-25 16:50:02 +01:00 committed by Mike Hearn
parent 68a614a33b
commit 4b035535e2
3 changed files with 10 additions and 4 deletions

View File

@ -691,7 +691,13 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca
peer.setMinProtocolVersion(vMinRequiredProtocolVersion); peer.setMinProtocolVersion(vMinRequiredProtocolVersion);
pendingPeers.add(peer); pendingPeers.add(peer);
channels.openConnection(address, peer); try {
channels.openConnection(address, peer);
} catch (Exception e) {
log.warn("Failed to connect to " + address + ": " + e.getMessage());
handlePeerDeath(peer);
return null;
}
peer.setSocketTimeout(vConnectTimeoutMillis); peer.setSocketTimeout(vConnectTimeoutMillis);
// When the channel has connected and version negotiated successfully, handleNewPeer will end up being called on // When the channel has connected and version negotiated successfully, handleNewPeer will end up being called on
// a worker thread. // a worker thread.

View File

@ -211,7 +211,7 @@ class ConnectionHandler implements MessageWriteTarget {
} catch (Exception e) { } catch (Exception e) {
// This can happen eg if the channel closes while the thread is about to get killed // This can happen eg if the channel closes while the thread is about to get killed
// (ClosedByInterruptException), or if handler.parser.receiveBytes throws something // (ClosedByInterruptException), or if handler.parser.receiveBytes throws something
log.error("Error handling SelectionKey", e); log.error("Error handling SelectionKey: " + e.getMessage());
if (handler != null) if (handler != null)
handler.closeConnection(); handler.closeConnection();
} }

View File

@ -64,11 +64,11 @@ public class NioClientManager extends AbstractExecutionThreadService implements
} }
} catch (IOException e) { } catch (IOException e) {
// Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself // Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
log.error("Failed to connect with exception", e); log.error("Failed to connect with exception: {}", e.getMessage());
handler.closeConnection(); handler.closeConnection();
} catch (CancelledKeyException e) { // There is a race to get to interestOps after finishConnect() which may cause this } catch (CancelledKeyException e) { // There is a race to get to interestOps after finishConnect() which may cause this
// Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself // Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
log.error("Failed to connect with exception", e); log.error("Failed to connect with exception: {}", e.getMessage());
handler.closeConnection(); handler.closeConnection();
} }
} else // Process bytes read } else // Process bytes read