Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Check if the connectFuture has completed successfully #293

Merged
merged 2 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable thr
: 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;
}
Expand All @@ -135,7 +135,7 @@ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable thr
} 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ public void shouldDisconnectForBreachOfProtocolWhenFramingExceptionThrown() thro

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();
}
}