Skip to content

Commit 0f1a04f

Browse files
committed
set correct default maxConnectionLifetimeInMs
com.ning.http.client.AsyncHttpClientConfigBean doesn't use com.ning.http.client.AsyncHttpClientConfig.Builder thus doesn't pick many default values, unluckily maxConnectionLifeTimeInMs is one of them, it's wrongly initialized to zero instead of -1, this bug will make org.asynchttpclient.providers.netty.channel.DefaultChannelPool.offer() close the cached http connection too early because "createTime + maxConnectionLifeTimeInMs < millisTime()". public boolean offer(String uri, Channel channel) { if (closed.get()) return false; if (!sslConnectionPoolEnabled && uri.startsWith("https")) { return false; } Long createTime = channel2CreationDate.get(channel); if (createTime == null) { channel2CreationDate.putIfAbsent(channel, millisTime()); ===> } else if (maxConnectionLifeTimeInMs != -1 && (createTime + maxConnectionLifeTimeInMs) < millisTime()) { log.debug("Channel {} expired", channel); return false; }
1 parent 63c5141 commit 0f1a04f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void configureDefaults() {
5151
idleConnectionInPoolTimeoutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultIdleConnectionInPoolTimeoutInMS", 60 * 1000);
5252
idleConnectionTimeoutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultIdleConnectionTimeoutInMS", 60 * 1000);
5353
requestTimeoutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultRequestTimeoutInMS", 60 * 1000);
54+
maxConnectionLifeTimeInMs = Integer.getInteger(ASYNC_CLIENT + "defaultMaxConnectionLifeTimeInMs", -1);
5455
redirectEnabled = Boolean.getBoolean(ASYNC_CLIENT + "defaultRedirectsEnabled");
5556
maxDefaultRedirects = Integer.getInteger(ASYNC_CLIENT + "defaultMaxRedirects", 5);
5657
compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled");
@@ -99,6 +100,11 @@ public AsyncHttpClientConfigBean setConnectionTimeOutInMs(int connectionTimeOutI
99100
return this;
100101
}
101102

103+
public AsyncHttpClientConfigBean setMaxConnectionLifeTimeInMs(int maxConnectionLifeTimeInMs) {
104+
this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs;
105+
return this;
106+
}
107+
102108
public AsyncHttpClientConfigBean setIdleConnectionInPoolTimeoutInMs(int idleConnectionInPoolTimeoutInMs) {
103109
this.idleConnectionInPoolTimeoutInMs = idleConnectionInPoolTimeoutInMs;
104110
return this;

0 commit comments

Comments
 (0)