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) {
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;
numRuleViolations = ruleViolations.getOrDefault(ruleViolation, 0);
@ -603,11 +603,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
ruleViolations.put(ruleViolation, numRuleViolations);
if (numRuleViolations >= ruleViolation.maxTolerance) {
log.warn("We close connection as we received too many corrupt requests.\n" +
"numRuleViolations={}\n\t" +
"corruptRequest={}\n\t" +
"corruptRequests={}\n\t" +
"connection={}", numRuleViolations, ruleViolation, ruleViolations, this);
log.warn("We close connection as we received too many corrupt requests. " +
"numRuleViolations={} " +
"corruptRequest={} " +
"corruptRequests={} " +
"connection with address{} and uid {}", numRuleViolations, ruleViolation, ruleViolations, this.getPeersNodeAddressProperty(), this.getUid());
this.ruleViolation = ruleViolation;
if (ruleViolation == RuleViolation.PEER_BANNED) {
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 Timer printStatisticsTimer;
private boolean shutDownRequested;
private int numOnConnections;
///////////////////////////////////////////////////////////////////////////////////////////
@ -216,6 +217,8 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
doHouseKeeping();
numOnConnections++;
if (lostAllConnections) {
lostAllConnections = false;
stopped = false;
@ -238,7 +241,8 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
boolean previousLostAllConnections = lostAllConnections;
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;
if (!shutDownRequested) {
@ -562,7 +566,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
if (!candidates.isEmpty()) {
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());
if (!connection.isStopped()) {
connection.shutDown(CloseConnectionReason.TOO_MANY_CONNECTIONS_OPEN,

View file

@ -136,7 +136,7 @@ public class GetDataRequestHandler {
@Override
public void onFailure(@NotNull Throwable throwable) {
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 + "." +
"Exception: " + throwable.getMessage();
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);