Skip to content

Commit 8b83790

Browse files
committed
Fix connectionPoolingWorks by setting skipping setConnectionTimeToLive is value is set to 0 since 0 is treated as Infinite timeToLive in Sdk and Apache 4.x but treated as immediate closeConnection in apache 5.x
1 parent 52fedbd commit 8b83790

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,17 @@ public PoolingHttpClientConnectionManager create(Apache5HttpClient.DefaultBuilde
694694
// TODO : Deprecated method needs to be removed with new replacements
695695
SSLConnectionSocketFactory sslsf = getPreferredSocketFactory(configuration, standardOptions);
696696

697-
PoolingHttpClientConnectionManager cm =
697+
PoolingHttpClientConnectionManagerBuilder builder =
698698
PoolingHttpClientConnectionManagerBuilder.create()
699699
.setSSLSocketFactory(sslsf)
700700
.setSchemePortResolver(DefaultSchemePortResolver.INSTANCE)
701-
.setDnsResolver(configuration.dnsResolver)
702-
.setConnectionTimeToLive(
703-
TimeValue.of(standardOptions.get(
704-
SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE).toMillis(),
705-
TimeUnit.MILLISECONDS))
706-
.build();
701+
.setDnsResolver(configuration.dnsResolver);
702+
Duration connectionTtl = standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE);
703+
if (!connectionTtl.isZero()) {
704+
// Skip TTL=0 to maintain backward compatibility (infinite in 4.x vs immediate expiration in 5.x)
705+
builder.setConnectionTimeToLive(TimeValue.of(connectionTtl.toMillis(), TimeUnit.MILLISECONDS));
706+
}
707+
PoolingHttpClientConnectionManager cm = builder.build();
707708

708709

709710
cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));

http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/Apache5HttpClientWireMockTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ public void credentialPlannerIsInvoked() throws Exception {
153153
mockProxyServer.verify(2, RequestPatternBuilder.allRequests());
154154
}
155155

156-
157-
@Override
158-
public void connectionPoolingWorks() throws Exception {
159-
// TODO : future PR will handle this.
160-
}
161-
162156
@Test
163157
public void overrideDnsResolver_WithDnsMatchingResolver_successful() throws Exception {
164158
overrideDnsResolver("magic.local.host");

0 commit comments

Comments
 (0)