Filter Netty native lib errors likewise the pure Java implementation (#3807)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/3816/head
Fabio Di Fabio 3 years ago committed by GitHub
parent de8eab8219
commit 386945984a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      ethereum/p2p/build.gradle
  3. 33
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java
  4. 62
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java
  5. 12
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java
  6. 1
      gradle/versions.gradle

@ -5,6 +5,7 @@
### Additions and Improvements
- GraphQL - allow null log topics in queries which match any topic [#3662](https://github.com/hyperledger/besu/pull/3662)
- multi-arch docker builds for amd64 and arm64 [#2954](https://github.com/hyperledger/besu/pull/2954)
- Filter Netty native lib errors likewise the pure Java implementation [#3807](https://github.com/hyperledger/besu/pull/3807)
### Bug Fixes
- Stop the BlockPropagationManager when it receives the TTD reached event [#3809](https://github.com/hyperledger/besu/pull/3809)

@ -40,8 +40,10 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'dnsjava:dnsjava'
implementation 'io.netty:netty-transport-native-unix-common'
implementation 'io.prometheus:simpleclient'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-crypto'
implementation('org.apache.tuweni:tuweni-devp2p') {

@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.p2p.discovery;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.tuweni.bytes.Bytes.wrapBuffer;
import org.hyperledger.besu.crypto.Hash;
import org.hyperledger.besu.crypto.NodeKey;
@ -45,8 +44,6 @@ import org.hyperledger.besu.util.NetworkUtility;
import org.hyperledger.besu.util.Subscribers;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@ -312,38 +309,16 @@ public abstract class PeerDiscoveryAgent {
.whenComplete(
(res, err) -> {
if (err != null) {
if (err instanceof SocketException && err.getMessage().contains("unreachable")) {
LOG.debug(
"Peer {} is unreachable, packet: {}", peer, wrapBuffer(packet.encode()), err);
} else if (err instanceof SocketException
&& err.getMessage().contentEquals("Operation not permitted")) {
LOG.debug(
"Operation not permitted sending to peer {}, this might be caused by firewall rules blocking traffic to a specific route.",
peer,
err);
} else if (err instanceof UnsupportedAddressTypeException) {
LOG.warn(
"Unsupported address type exception when connecting to peer {}, this is likely due to ipv6 not being enabled at runtime. "
+ "Set logging level to TRACE to see full stacktrace",
peer);
LOG.trace(
"Sending to peer {} failed, packet: {}, stacktrace: {}",
peer,
wrapBuffer(packet.encode()),
err);
} else {
LOG.warn(
"Sending to peer {} failed, packet: {}",
peer,
wrapBuffer(packet.encode()),
err);
}
handleOutgoingPacketError(err, peer, packet);
return;
}
peer.setLastContacted(System.currentTimeMillis());
});
}
protected abstract void handleOutgoingPacketError(
final Throwable err, final DiscoveryPeer peer, final Packet packet);
public Stream<DiscoveryPeer> streamDiscoveredPeers() {
return controller.map(PeerDiscoveryController::streamDiscoveredPeers).orElse(Stream.empty());
}

@ -15,6 +15,9 @@
package org.hyperledger.besu.ethereum.p2p.discovery;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.tuweni.bytes.Bytes.wrapBuffer;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
@ -34,6 +37,7 @@ import java.io.IOException;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@ -42,6 +46,8 @@ import java.util.function.Supplier;
import java.util.stream.StreamSupport;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.unix.Errors;
import io.netty.channel.unix.Errors.NativeIoException;
import io.netty.util.concurrent.SingleThreadEventExecutor;
import io.vertx.core.AsyncResult;
import io.vertx.core.Vertx;
@ -196,6 +202,60 @@ public class VertxPeerDiscoveryAgent extends PeerDiscoveryAgent {
return completion;
}
@Override
protected void handleOutgoingPacketError(
final Throwable err, final DiscoveryPeer peer, final Packet packet) {
if (err instanceof NativeIoException) {
final var nativeErr = (NativeIoException) err;
if (nativeErr.expectedErr() == Errors.ERROR_ENETUNREACH_NEGATIVE) {
debugLambda(
LOG,
"Peer {} is unreachable, native error code {}, packet: {}, stacktrace: {}",
peer::toString,
nativeErr::expectedErr,
() -> wrapBuffer(packet.encode()),
err::toString);
} else {
LOG.warn(
"Sending to peer {} failed, native error code {}, packet: {}, stacktrace: {}",
peer,
nativeErr.expectedErr(),
wrapBuffer(packet.encode()),
err);
}
} else if (err instanceof SocketException && err.getMessage().contains("unreachable")) {
debugLambda(
LOG,
"Peer {} is unreachable, packet: {}",
peer::toString,
() -> wrapBuffer(packet.encode()),
err::toString);
} else if (err instanceof SocketException
&& err.getMessage().contentEquals("Operation not permitted")) {
LOG.debug(
"Operation not permitted sending to peer {}, this might be caused by firewall rules blocking traffic to a specific route.",
peer,
err);
} else if (err instanceof UnsupportedAddressTypeException) {
LOG.warn(
"Unsupported address type exception when connecting to peer {}, this is likely due to ipv6 not being enabled at runtime. "
+ "Set logging level to TRACE to see full stacktrace",
peer);
traceLambda(
LOG,
"Sending to peer {} failed, packet: {}, stacktrace: {}",
peer::toString,
() -> wrapBuffer(packet.encode()),
err::toString);
} else {
LOG.warn(
"Sending to peer {} failed, packet: {}, stacktrace: {}",
peer,
wrapBuffer(packet.encode()),
err);
}
}
/**
* For uncontrolled exceptions occurring in the packet handlers.
*
@ -217,7 +277,7 @@ public class VertxPeerDiscoveryAgent extends PeerDiscoveryAgent {
private void handlePacket(final DatagramPacket datagram) {
final int length = datagram.data().length();
if (!validatePacketSize(length)) {
LOG.debug("Discarding over-sized packet. Actual size (bytes): " + length);
LOG.debug("Discarding over-sized packet. Actual size (bytes): {}", length);
return;
}
vertx.<Packet>executeBlocking(

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.p2p.discovery.internal;
import static org.apache.tuweni.bytes.Bytes.wrapBuffer;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
@ -142,6 +144,16 @@ public class MockPeerDiscoveryAgent extends PeerDiscoveryAgent {
return CompletableFuture.completedFuture(null);
}
@Override
protected void handleOutgoingPacketError(
final Throwable err, final DiscoveryPeer peer, final Packet packet) {
LOG.warn(
"Sending to peer {} failed, packet: {}, stacktrace: {}",
peer,
wrapBuffer(packet.encode()),
err);
}
public NodeKey getNodeKey() {
return nodeKey;
}

@ -70,6 +70,7 @@ dependencyManagement {
dependency 'io.netty:netty-tcnative-boringssl-static:2.0.50.Final'
dependency group: 'io.netty', name: 'netty-transport-native-epoll', version:'4.1.74.Final', classifier: 'linux-x86_64'
dependency group: 'io.netty', name: 'netty-transport-native-kqueue', version:'4.1.74.Final', classifier: 'osx-x86_64'
dependency 'io.netty:netty-transport-native-unix-common:4.1.74.Final'
dependency 'io.opentelemetry:opentelemetry-api:1.6.0'
dependency 'io.opentelemetry:opentelemetry-exporter-otlp-metrics:1.6.0-alpha'

Loading…
Cancel
Save