Merge pull request #6510 from HenrikJannsen/improve_connection_logs

Improvements in connection and increase timeout
This commit is contained in:
Alejandro García 2023-01-12 16:33:40 +00:00 committed by GitHub
commit d859f391bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 20 deletions

View File

@ -46,7 +46,7 @@ import org.jetbrains.annotations.Nullable;
@Slf4j @Slf4j
abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res extends GetStateHashesResponse> implements MessageListener { abstract class RequestStateHashesHandler<Req extends GetStateHashesRequest, Res extends GetStateHashesResponse> implements MessageListener {
private static final long TIMEOUT = 120; private static final long TIMEOUT = 180;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -202,6 +202,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
if (peersNodeAddress != null) { if (peersNodeAddress != null) {
setPeersNodeAddress(peersNodeAddress); setPeersNodeAddress(peersNodeAddress);
if (networkFilter != null && networkFilter.isPeerBanned(peersNodeAddress)) { if (networkFilter != null && networkFilter.isPeerBanned(peersNodeAddress)) {
log.warn("We created an outbound connection with a banned peer");
reportInvalidRequest(RuleViolation.PEER_BANNED); reportInvalidRequest(RuleViolation.PEER_BANNED);
} }
} }
@ -232,6 +233,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
if (networkFilter != null && if (networkFilter != null &&
peersNodeAddressOptional.isPresent() && peersNodeAddressOptional.isPresent() &&
networkFilter.isPeerBanned(peersNodeAddressOptional.get())) { networkFilter.isPeerBanned(peersNodeAddressOptional.get())) {
log.warn("We tried to send a message to a banned peer. message={}", networkEnvelope.getClass().getSimpleName());
reportInvalidRequest(RuleViolation.PEER_BANNED); reportInvalidRequest(RuleViolation.PEER_BANNED);
return; return;
} }
@ -398,9 +400,12 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
List<NetworkEnvelope> networkEnvelopes = bundleOfEnvelopes.getEnvelopes(); List<NetworkEnvelope> networkEnvelopes = bundleOfEnvelopes.getEnvelopes();
for (NetworkEnvelope networkEnvelope : networkEnvelopes) { for (NetworkEnvelope networkEnvelope : networkEnvelopes) {
// If SendersNodeAddressMessage we do some verifications and apply if successful, otherwise we return false. // If SendersNodeAddressMessage we do some verifications and apply if successful, otherwise we return false.
if (networkEnvelope instanceof SendersNodeAddressMessage && if (networkEnvelope instanceof SendersNodeAddressMessage) {
!processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope)) { boolean isValid = processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope);
continue; if (!isValid) {
log.warn("Received an invalid {} at processing BundleOfEnvelopes", networkEnvelope.getClass().getSimpleName());
continue;
}
} }
if (networkEnvelope instanceof AddPersistableNetworkPayloadMessage) { if (networkEnvelope instanceof AddPersistableNetworkPayloadMessage) {
@ -604,13 +609,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
if (numRuleViolations >= ruleViolation.maxTolerance) { if (numRuleViolations >= ruleViolation.maxTolerance) {
log.warn("We close connection as we received too many corrupt requests. " + log.warn("We close connection as we received too many corrupt requests. " +
"numRuleViolations={} " + "ruleViolations={} " +
"corruptRequest={} " + "connection with address{} and uid {}", ruleViolations, peersNodeAddressProperty, uid);
"corruptRequests={} " +
"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.debug("We close connection due RuleViolation.PEER_BANNED. peersNodeAddress={}", getPeersNodeAddressOptional());
shutDown(CloseConnectionReason.PEER_BANNED); shutDown(CloseConnectionReason.PEER_BANNED);
} else if (ruleViolation == RuleViolation.INVALID_CLASS) { } else if (ruleViolation == RuleViolation.INVALID_CLASS) {
log.warn("We close connection due RuleViolation.INVALID_CLASS"); log.warn("We close connection due RuleViolation.INVALID_CLASS");
@ -678,6 +681,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
} }
if (networkFilter != null && networkFilter.isPeerBanned(senderNodeAddress)) { if (networkFilter != null && networkFilter.isPeerBanned(senderNodeAddress)) {
log.warn("We got a message from a banned peer. message={}", sendersNodeAddressMessage.getClass().getSimpleName());
reportInvalidRequest(RuleViolation.PEER_BANNED); reportInvalidRequest(RuleViolation.PEER_BANNED);
return false; return false;
} }
@ -701,10 +705,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
@Override @Override
public void run() { public void run() {
try { try {
Thread.currentThread().setName("InputHandler"); Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(uid, 15));
while (!stopped && !Thread.currentThread().isInterrupted()) { while (!stopped && !Thread.currentThread().isInterrupted()) {
if (!threadNameSet && getPeersNodeAddressOptional().isPresent()) { if (!threadNameSet && getPeersNodeAddressOptional().isPresent()) {
Thread.currentThread().setName("InputHandler-" + getPeersNodeAddressOptional().get().getFullAddress()); Thread.currentThread().setName("InputHandler-" + Utilities.toTruncatedString(getPeersNodeAddressOptional().get().getFullAddress(), 15));
threadNameSet = true; threadNameSet = true;
} }
try { try {
@ -743,6 +747,8 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
if (networkFilter != null && if (networkFilter != null &&
peersNodeAddressOptional.isPresent() && peersNodeAddressOptional.isPresent() &&
networkFilter.isPeerBanned(peersNodeAddressOptional.get())) { networkFilter.isPeerBanned(peersNodeAddressOptional.get())) {
log.warn("We got a message from a banned peer. proto={}", Utilities.toTruncatedString(proto));
reportInvalidRequest(RuleViolation.PEER_BANNED); reportInvalidRequest(RuleViolation.PEER_BANNED);
return; return;
} }
@ -828,9 +834,15 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
// If SendersNodeAddressMessage we do some verifications and apply if successful, // If SendersNodeAddressMessage we do some verifications and apply if successful,
// otherwise we return false. // otherwise we return false.
if (networkEnvelope instanceof SendersNodeAddressMessage && if (networkEnvelope instanceof SendersNodeAddressMessage) {
!processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope)) { boolean isValid = processSendersNodeAddressMessage((SendersNodeAddressMessage) networkEnvelope);
return; if (!isValid) {
return;
}
}
if (!(networkEnvelope instanceof SendersNodeAddressMessage) && peersNodeAddressOptional.isEmpty()) {
log.info("We got a {} from a peer with yet unknown address on connection with uid={}", networkEnvelope.getClass().getSimpleName(), uid);
} }
onMessage(networkEnvelope, this); onMessage(networkEnvelope, this);
@ -842,7 +854,6 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
reportInvalidRequest(RuleViolation.INVALID_CLASS); reportInvalidRequest(RuleViolation.INVALID_CLASS);
} catch (ProtobufferException | NoClassDefFoundError | InvalidProtocolBufferException e) { } catch (ProtobufferException | NoClassDefFoundError | InvalidProtocolBufferException e) {
log.error(e.getMessage()); log.error(e.getMessage());
e.printStackTrace();
reportInvalidRequest(RuleViolation.INVALID_DATA_TYPE); reportInvalidRequest(RuleViolation.INVALID_DATA_TYPE);
} catch (Throwable t) { } catch (Throwable t) {
handleException(t); handleException(t);

View File

@ -141,8 +141,7 @@ public abstract class NetworkNode implements MessageListener {
SettableFuture<Connection> resultFuture = SettableFuture.create(); SettableFuture<Connection> resultFuture = SettableFuture.create();
ListenableFuture<Connection> future = connectionExecutor.submit(() -> { ListenableFuture<Connection> future = connectionExecutor.submit(() -> {
Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + peersNodeAddress.getFullAddress()); Thread.currentThread().setName("NetworkNode.connectionExecutor:SendMessage-to-" + Utilities.toTruncatedString(peersNodeAddress.getFullAddress(), 15));
if (peersNodeAddress.equals(getNodeAddress())) { if (peersNodeAddress.equals(getNodeAddress())) {
log.warn("We are sending a message to ourselves"); log.warn("We are sending a message to ourselves");
} }
@ -305,7 +304,8 @@ public abstract class NetworkNode implements MessageListener {
try { try {
ListenableFuture<Connection> future = executor.submit(() -> { ListenableFuture<Connection> future = executor.submit(() -> {
String id = connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get().getFullAddress() : connection.getUid(); String id = connection.getPeersNodeAddressOptional().isPresent() ? connection.getPeersNodeAddressOptional().get().getFullAddress() : connection.getUid();
Thread.currentThread().setName("NetworkNode:SendMessage-to-" + id); Thread.currentThread().setName("NetworkNode:SendMessage-to-" + Utilities.toTruncatedString(id, 15));
connection.sendMessage(networkEnvelope); connection.sendMessage(networkEnvelope);
return connection; return connection;
}); });

View File

@ -234,7 +234,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
@Override @Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) { public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
log.info("onDisconnect called: nodeAddress={}, closeConnectionReason={}", log.debug("onDisconnect called: nodeAddress={}, closeConnectionReason={}",
connection.getPeersNodeAddressOptional(), closeConnectionReason); connection.getPeersNodeAddressOptional(), closeConnectionReason);
handleConnectionFault(connection); handleConnectionFault(connection);

View File

@ -136,7 +136,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener,
@Override @Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) { public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
log.info("onDisconnect closeConnectionReason={}, nodeAddressOpt={}", closeConnectionReason, connection.getPeersNodeAddressOptional()); log.debug("onDisconnect closeConnectionReason={}, nodeAddressOpt={}", closeConnectionReason, connection.getPeersNodeAddressOptional());
closeHandler(connection); closeHandler(connection);
if (retryTimer == null) { if (retryTimer == null) {