Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-8c2f4c2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"description": "Map connection reset and aborted socket exceptions in NettyUtils to decorate closed channel exceptions across operating systems",
"contributor": "reginaldalfret"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.time.Duration;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -92,10 +93,17 @@ public static Throwable decorateException(Channel channel, Throwable originalCau
}

private static boolean isConnectionResetException(Throwable originalCause) {
if (!(originalCause instanceof IOException)) {
return false;
}
String message = originalCause.getMessage();
return originalCause instanceof IOException &&
message != null &&
message.contains("Connection reset by peer");
if (message == null) {
return false;
}
String lowerMessage = message.toLowerCase(Locale.ENGLISH);
return lowerMessage.contains("connection reset") ||
lowerMessage.contains("forcibly closed by the remote host") ||
lowerMessage.contains("connection was aborted");
}

private static boolean isAcquireTimeoutException(Throwable originalCause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
import java.io.IOException;
import java.net.SocketException;
import java.nio.channels.ClosedChannelException;
import java.time.Duration;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -378,4 +379,48 @@ public void decorateException_with_IOException_noMsg() {
assertThat(output).isInstanceOf(IOException.class);
assertThat(output.getCause()).isNull();
}

@Test
public void decorateException_with_SocketException_connectionReset() {
Channel channel = mock(Channel.class);
Throwable connectionResetException = new SocketException("Connection reset");
Throwable output = NettyUtils.decorateException(channel, connectionResetException);

assertThat(output).isInstanceOf(IOException.class);
assertThat(output.getCause()).isSameAs(connectionResetException);
assertThat(output.getMessage()).contains(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}

@Test
public void decorateException_with_IOException_forciblyClosed() {
Channel channel = mock(Channel.class);
Throwable forciblyClosedException = new IOException("An existing connection was forcibly closed by the remote host");
Throwable output = NettyUtils.decorateException(channel, forciblyClosedException);

assertThat(output).isInstanceOf(IOException.class);
assertThat(output.getCause()).isSameAs(forciblyClosedException);
assertThat(output.getMessage()).contains(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}

@Test
public void decorateException_with_IOException_lowercaseReset() {
Channel channel = mock(Channel.class);
Throwable lowerCaseResetException = new IOException("read error: connection reset");
Throwable output = NettyUtils.decorateException(channel, lowerCaseResetException);

assertThat(output).isInstanceOf(IOException.class);
assertThat(output.getCause()).isSameAs(lowerCaseResetException);
assertThat(output.getMessage()).contains(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}

@Test
public void decorateException_with_IOException_connectionAborted() {
Channel channel = mock(Channel.class);
Throwable connectionAbortedException = new IOException("An established connection was aborted by the software in your host machine");
Throwable output = NettyUtils.decorateException(channel, connectionAbortedException);

assertThat(output).isInstanceOf(IOException.class);
assertThat(output.getCause()).isSameAs(connectionAbortedException);
assertThat(output.getMessage()).contains(NettyUtils.CLOSED_CHANNEL_ERROR_MESSAGE);
}
}