Skip to content

Commit 329dd4d

Browse files
authored
expose crt connection timeout (#5835)
* expose connectionAqusitionTimeout in crtHttpClient * dependency version changed * changelog added * rollback to test * change added back * changed the default connectionacquiretimeout value * changed value back * test case config changed * invalid input testcases added * changelog modified
1 parent ed828fd commit 329dd4d

File tree

7 files changed

+49
-2
lines changed

7 files changed

+49
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS CRT HTTP Client",
4+
"contributor": "",
5+
"description": "Allow users to configure connectionAcquisitionTimeout for AwsCrtHttpClient and AwsCrtAsyncHttpClient"
6+
}

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ AwsCrtAsyncHttpClient.Builder connectionHealthConfiguration(Consumer<ConnectionH
182182
*/
183183
AwsCrtAsyncHttpClient.Builder connectionTimeout(Duration connectionTimeout);
184184

185+
/**
186+
* The amount of time to wait when acquiring a connection from the pool before giving up and timing out.
187+
* @param connectionAcquisitionTimeout the timeout duration
188+
* @return this builder for method chaining.
189+
*/
190+
AwsCrtAsyncHttpClient.Builder connectionAcquisitionTimeout(Duration connectionAcquisitionTimeout);
191+
185192
/**
186193
* Configure whether to enable {@code tcpKeepAlive} and relevant configuration for all connections established by this
187194
* client.

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtHttpClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ AwsCrtHttpClient.Builder connectionHealthConfiguration(Consumer<ConnectionHealth
225225
*/
226226
AwsCrtHttpClient.Builder connectionTimeout(Duration connectionTimeout);
227227

228+
/**
229+
* The amount of time to wait when acquiring a connection from the pool before giving up and timing out.
230+
* @param connectionAcquisitionTimeout the timeout duration
231+
* @return this builder for method chaining.
232+
*/
233+
AwsCrtHttpClient.Builder connectionAcquisitionTimeout(Duration connectionAcquisitionTimeout);
234+
228235
/**
229236
* Configure whether to enable {@code tcpKeepAlive} and relevant configuration for all connections established by this
230237
* client.

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ abstract class AwsCrtHttpClientBase implements SdkAutoCloseable {
6565
private final HttpMonitoringOptions monitoringOptions;
6666
private final long maxConnectionIdleInMilliseconds;
6767
private final int maxConnectionsPerEndpoint;
68+
private final long connectionAcquisitionTimeout;
6869
private boolean isClosed = false;
6970

7071
AwsCrtHttpClientBase(AwsCrtClientBuilderBase builder, AttributeMap config) {
@@ -90,6 +91,7 @@ abstract class AwsCrtHttpClientBase implements SdkAutoCloseable {
9091
this.maxConnectionsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS);
9192
this.monitoringOptions = resolveHttpMonitoringOptions(builder.getConnectionHealthConfiguration()).orElse(null);
9293
this.maxConnectionIdleInMilliseconds = config.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis();
94+
this.connectionAcquisitionTimeout = config.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT).toMillis();
9395
this.proxyOptions = resolveProxy(builder.getProxyConfiguration(), tlsContext).orElse(null);
9496
}
9597
}
@@ -126,7 +128,8 @@ private HttpClientConnectionManager createConnectionPool(URI uri) {
126128
.withManualWindowManagement(true)
127129
.withProxyOptions(proxyOptions)
128130
.withMonitoringOptions(monitoringOptions)
129-
.withMaxConnectionIdleInMilliseconds(maxConnectionIdleInMilliseconds);
131+
.withMaxConnectionIdleInMilliseconds(maxConnectionIdleInMilliseconds)
132+
.withConnectionAcquisitionTimeoutInMilliseconds(connectionAcquisitionTimeout);
130133

131134
return HttpClientConnectionManager.create(options);
132135
}

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/AwsCrtClientBuilderBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public BuilderT connectionTimeout(Duration connectionTimeout) {
100100
return thisBuilder();
101101
}
102102

103+
public BuilderT connectionAcquisitionTimeout(Duration connectionAcquisitionTimeout) {
104+
Validate.isPositive(connectionAcquisitionTimeout, "connectionAcquisitionTimeout");
105+
standardOptions.put(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT, connectionAcquisitionTimeout);
106+
return thisBuilder();
107+
}
108+
103109
public BuilderT tcpKeepAliveConfiguration(TcpKeepAliveConfiguration tcpKeepAliveConfiguration) {
104110
this.tcpKeepAliveConfiguration = tcpKeepAliveConfiguration;
105111
return thisBuilder();

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515

1616
package software.amazon.awssdk.http.crt;
1717

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1819
import static software.amazon.awssdk.http.SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES;
1920

2021

22+
import java.time.Duration;
23+
import org.junit.Test;
2124
import org.junit.jupiter.api.AfterAll;
2225
import org.junit.jupiter.api.BeforeAll;
26+
2327
import software.amazon.awssdk.crt.CrtResource;
2428
import software.amazon.awssdk.crt.Log;
2529
import software.amazon.awssdk.http.SdkHttpClient;
@@ -42,13 +46,27 @@ public static void afterAll() {
4246
CrtResource.waitForNoResources();
4347
}
4448

49+
/**
50+
* default value of connectionAcquisitionTimeout of 10 will fail validatesHttpsCertificateIssuer() test
51+
* */
4552
@Override
4653
protected SdkHttpClient createSdkHttpClient(SdkHttpClientOptions options) {
4754
boolean trustAllCerts = options.trustAll();
4855
return AwsCrtHttpClient.builder()
56+
.connectionAcquisitionTimeout(Duration.ofSeconds(40))
4957
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, trustAllCerts).build());
5058
}
5159

60+
@Test
61+
public void negativeConnectionAcquisitionTimeout_shouldFail() {
62+
assertThatThrownBy(() -> {
63+
SdkHttpClient client = AwsCrtHttpClient.builder()
64+
.connectionAcquisitionTimeout(Duration.ofSeconds(-1))
65+
.build();
66+
client.close();
67+
}).hasMessage("connectionAcquisitionTimeout must be positive");
68+
}
69+
5270
// Empty test; behavior not supported when using custom factory
5371
@Override
5472
public void testCustomTlsTrustManagerAndTrustAllFails() {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<rxjava.version>2.2.21</rxjava.version>
125125
<commons-codec.verion>1.17.1</commons-codec.verion>
126126
<jmh.version>1.37</jmh.version>
127-
<awscrt.version>0.33.6</awscrt.version>
127+
<awscrt.version>0.33.9</awscrt.version>
128128

129129
<!--Test dependencies -->
130130
<junit5.version>5.10.0</junit5.version>

0 commit comments

Comments
 (0)