Skip to content

Update default connectionMaxIdleTimeout for NettyNioAsyncClient #1510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
@@ -0,0 +1,5 @@
{
"category": "Netty NIO HTTP Client",
"type": "bugfix",
"description": "Update default connectionMaxIdleTimeout of NettyNioAsyncClient to 5 seconds"
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
private static final Logger log = LoggerFactory.getLogger(NettyNioAsyncHttpClient.class);
private static final long MAX_STREAMS_ALLOWED = 4294967295L; // unsigned 32-bit, 2^32 -1

// Override connection idle timeout for Netty http client to reduce the frequency of "server failed to complete the
// response error". see https://github.com/aws/aws-sdk-java-v2/issues/1122
private static final AttributeMap NETTY_HTTP_DEFAULTS = AttributeMap.builder()
.put(CONNECTION_MAX_IDLE_TIMEOUT, Duration.ofSeconds(5))
.build();

private final SdkEventLoopGroup sdkEventLoopGroup;
private final SdkChannelPoolMap<URI, ? extends ChannelPool> pools;
private final NettyConfiguration configuration;
Expand Down Expand Up @@ -175,6 +181,11 @@ public String clientName() {
return CLIENT_NAME;
}

@SdkTestInternalApi
NettyConfiguration configuration() {
return configuration;
}

/**
* Builder that allows configuration of the Netty NIO HTTP implementation. Use {@link #builder()} to configure and construct
* a Netty HTTP client.
Expand Down Expand Up @@ -561,6 +572,7 @@ public Builder tlsKeyManagersProvider(TlsKeyManagersProvider tlsKeyManagersProvi
public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
return new NettyNioAsyncHttpClient(this, standardOptions.build()
.merge(serviceDefaults)
.merge(NETTY_HTTP_DEFAULTS)
.merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ public static void tearDown() throws Exception {
client.close();
}

@Test
public void defaultConnectionIdleTimeout() {
try (NettyNioAsyncHttpClient client = (NettyNioAsyncHttpClient) NettyNioAsyncHttpClient.builder().build()) {
assertThat(client.configuration().idleTimeoutMillis()).isEqualTo(5000);
}
}

@Test
public void overrideConnectionIdleTimeout_shouldHonor() {
try (NettyNioAsyncHttpClient client = (NettyNioAsyncHttpClient) NettyNioAsyncHttpClient.builder()
.connectionMaxIdleTime(Duration.ofMillis(1000))
.build()) {
assertThat(client.configuration().idleTimeoutMillis()).isEqualTo(1000);
}
}

@Test
public void customFactoryIsUsed() throws Exception {
ThreadFactory threadFactory = spy(new CustomThreadFactory());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"deleteDashboards",
"putDashboard",
"getDashboard"
],
"serviceSpecificHttpConfig": "software.amazon.awssdk.services.cloudwatch.internal.CloudWatchHttpConfigurationOptions"
]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@
"createMethodParams": [
"clientConfiguration"
]
},
"serviceSpecificHttpConfig": "software.amazon.awssdk.services.s3.internal.S3HttpConfigurationOptions"
}
}