diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java index 2a0499fdad..f4761c1bff 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramer.java @@ -190,7 +190,7 @@ final class DeFramer extends ByteToMessageDecoder { throwable instanceof DecoderException && throwable.getCause() != null ? throwable.getCause() : throwable; - if (cause instanceof FramingException) { + if (cause instanceof FramingException || cause instanceof RLPException) { LOG.debug("Invalid incoming message", throwable); if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) { connectFuture.get().disconnect(DisconnectReason.BREACH_OF_PROTOCOL); diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java index c95e663d49..2d4df5fa3b 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/DeFramerTest.java @@ -43,6 +43,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.Discon import tech.pegasys.pantheon.ethereum.p2p.wire.messages.HelloMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.PingMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.WireMessageCodes; +import tech.pegasys.pantheon.ethereum.rlp.RLPException; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -123,6 +124,16 @@ public class DeFramerTest { verify(peerConnection).disconnect(DisconnectReason.BREACH_OF_PROTOCOL); } + @Test + public void exceptionCaught_shouldDisconnectForBreachOfProtocolWhenRlpExceptionThrown() + throws Exception { + connectFuture.complete(peerConnection); + + deFramer.exceptionCaught(ctx, new DecoderException(new RLPException("Test"))); + + verify(peerConnection).disconnect(DisconnectReason.BREACH_OF_PROTOCOL); + } + @Test public void exceptionCaught_shouldHandleFramingExceptionWhenFutureCompletedExceptionally() throws Exception {