Check if the connectFuture has completed successfully properly. (#293)

Avoids throwing java.util.concurrent.ExecutionException when handling other framing errors in DeFramer.
Adrian Sutton 6 years ago committed by GitHub
parent 56e5f7e2a5
commit 448e465f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramer.java
  2. 18
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/netty/DeFramerTest.java

@ -125,7 +125,7 @@ final class DeFramer extends ByteToMessageDecoder {
: throwable;
if (cause instanceof FramingException) {
LOG.debug("Invalid incoming message", throwable);
if (connectFuture.isDone()) {
if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) {
connectFuture.get().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
return;
}
@ -135,7 +135,7 @@ final class DeFramer extends ByteToMessageDecoder {
} else {
LOG.error("Exception while processing incoming message", throwable);
}
if (connectFuture.isDone()) {
if (connectFuture.isDone() && !connectFuture.isCompletedExceptionally()) {
connectFuture.get().terminateConnection(DisconnectReason.TCP_SUBSYSTEM_ERROR, false);
} else {
connectFuture.completeExceptionally(throwable);

@ -52,4 +52,22 @@ public class DeFramerTest {
verify(peerConnection).disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
}
@Test
public void shouldHandleFramingExceptionWhenFutureCompletedExceptionally() throws Exception {
connectFuture.completeExceptionally(new Exception());
deFramer.exceptionCaught(ctx, new DecoderException(new FramingException("Test")));
verify(ctx).close();
}
@Test
public void shouldHandleGenericExceptionWhenFutureCompletedExceptionally() throws Exception {
connectFuture.completeExceptionally(new Exception());
deFramer.exceptionCaught(ctx, new DecoderException(new RuntimeException("Test")));
verify(ctx).close();
}
}

Loading…
Cancel
Save