Improve/cleanup logs.

Only log lostAllConnections after numOnConnections > 2 to avoid logs at startup

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2022-12-16 17:48:58 -05:00
parent c3acd5fb4a
commit 1030f891b9
No known key found for this signature in database
GPG key ID: 02AA2BAE387C8307
3 changed files with 13 additions and 9 deletions

View file

@ -595,7 +595,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
public boolean reportInvalidRequest(RuleViolation ruleViolation) { public boolean reportInvalidRequest(RuleViolation ruleViolation) {
log.warn("We got reported the ruleViolation {} at connection {}", ruleViolation, this); log.info("We got reported the ruleViolation {} at connection with address{} and uid {}", ruleViolation, this.getPeersNodeAddressProperty(), this.getUid());
int numRuleViolations; int numRuleViolations;
numRuleViolations = ruleViolations.getOrDefault(ruleViolation, 0); numRuleViolations = ruleViolations.getOrDefault(ruleViolation, 0);
@ -603,11 +603,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
ruleViolations.put(ruleViolation, numRuleViolations); ruleViolations.put(ruleViolation, numRuleViolations);
if (numRuleViolations >= ruleViolation.maxTolerance) { if (numRuleViolations >= ruleViolation.maxTolerance) {
log.warn("We close connection as we received too many corrupt requests.\n" + log.warn("We close connection as we received too many corrupt requests. " +
"numRuleViolations={}\n\t" + "numRuleViolations={} " +
"corruptRequest={}\n\t" + "corruptRequest={} " +
"corruptRequests={}\n\t" + "corruptRequests={} " +
"connection={}", numRuleViolations, ruleViolation, ruleViolations, this); "connection with address{} and uid {}", numRuleViolations, ruleViolation, ruleViolations, this.getPeersNodeAddressProperty(), this.getUid());
this.ruleViolation = ruleViolation; this.ruleViolation = ruleViolation;
if (ruleViolation == RuleViolation.PEER_BANNED) { if (ruleViolation == RuleViolation.PEER_BANNED) {
log.warn("We close connection due RuleViolation.PEER_BANNED. peersNodeAddress={}", getPeersNodeAddressOptional()); log.warn("We close connection due RuleViolation.PEER_BANNED. peersNodeAddress={}", getPeersNodeAddressOptional());

View file

@ -84,6 +84,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
private static final boolean PRINT_REPORTED_PEERS_DETAILS = true; private static final boolean PRINT_REPORTED_PEERS_DETAILS = true;
private Timer printStatisticsTimer; private Timer printStatisticsTimer;
private boolean shutDownRequested; private boolean shutDownRequested;
private int numOnConnections;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -216,6 +217,8 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
doHouseKeeping(); doHouseKeeping();
numOnConnections++;
if (lostAllConnections) { if (lostAllConnections) {
lostAllConnections = false; lostAllConnections = false;
stopped = false; stopped = false;
@ -238,7 +241,8 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
boolean previousLostAllConnections = lostAllConnections; boolean previousLostAllConnections = lostAllConnections;
lostAllConnections = networkNode.getAllConnections().isEmpty(); lostAllConnections = networkNode.getAllConnections().isEmpty();
if (lostAllConnections) { // At start-up we ignore if we would lose a connection and would fall back to no connections
if (lostAllConnections && numOnConnections > 2) {
stopped = true; stopped = true;
if (!shutDownRequested) { if (!shutDownRequested) {
@ -562,7 +566,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
if (!candidates.isEmpty()) { if (!candidates.isEmpty()) {
Connection connection = candidates.remove(0); Connection connection = candidates.remove(0);
log.info("checkMaxConnections: Num candidates for shut down={}. We close oldest connection to peer {}", log.info("checkMaxConnections: Num candidates (inbound/peer) for shut down={}. We close oldest connection to peer {}",
candidates.size(), connection.getPeersNodeAddressOptional()); candidates.size(), connection.getPeersNodeAddressOptional());
if (!connection.isStopped()) { if (!connection.isStopped()) {
connection.shutDown(CloseConnectionReason.TOO_MANY_CONNECTIONS_OPEN, connection.shutDown(CloseConnectionReason.TOO_MANY_CONNECTIONS_OPEN,

View file

@ -136,7 +136,7 @@ public class GetDataRequestHandler {
@Override @Override
public void onFailure(@NotNull Throwable throwable) { public void onFailure(@NotNull Throwable throwable) {
if (!stopped) { if (!stopped) {
String errorMessage = "Sending getDataRequest to " + connection + String errorMessage = "Sending getDataResponse to " + connection +
" failed. That is expected if the peer is offline. getDataResponse=" + getDataResponse + "." + " failed. That is expected if the peer is offline. getDataResponse=" + getDataResponse + "." +
"Exception: " + throwable.getMessage(); "Exception: " + throwable.getMessage();
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection); handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);