Skip to content

Commit 5ca4fa4

Browse files
author
Stephane Landelle
committed
IdleChannelDetector should remove empty queues, close AsyncHttpClient#676
1 parent 1786d05 commit 5ca4fa4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/pool/DefaultChannelPool.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
package org.asynchttpclient.providers.netty.channel.pool;
1515

1616
import static org.asynchttpclient.util.DateUtils.millisTime;
17-
18-
import org.asynchttpclient.AsyncHttpClientConfig;
19-
import org.asynchttpclient.providers.netty.channel.Channels;
20-
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
23-
2417
import io.netty.channel.Channel;
2518
import io.netty.util.Timeout;
2619
import io.netty.util.Timer;
@@ -29,11 +22,18 @@
2922
import java.util.ArrayList;
3023
import java.util.Collections;
3124
import java.util.List;
25+
import java.util.Map;
3226
import java.util.concurrent.ConcurrentHashMap;
3327
import java.util.concurrent.ConcurrentLinkedQueue;
3428
import java.util.concurrent.TimeUnit;
3529
import java.util.concurrent.atomic.AtomicBoolean;
3630

31+
import org.asynchttpclient.AsyncHttpClientConfig;
32+
import org.asynchttpclient.providers.netty.channel.Channels;
33+
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
36+
3737
/**
3838
* A simple implementation of {@link com.ning.http.client.providers.netty.pool.ChannelPool} based on a {@link java.util.concurrent.ConcurrentHashMap}
3939
*/
@@ -198,15 +198,19 @@ public void run(Timeout timeout) throws Exception {
198198
int closedCount = 0;
199199
int totalCount = 0;
200200

201-
for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) {
201+
for (Map.Entry<String, ConcurrentLinkedQueue<IdleChannel>> entry : poolsPerKey.entrySet()) {
202+
203+
String poolKey = entry.getKey();
204+
ConcurrentLinkedQueue<IdleChannel> pool = entry.getValue();
202205
// store in intermediate unsynchronized lists to minimize the impact on the ConcurrentLinkedQueue
203206
if (LOGGER.isDebugEnabled())
204207
totalCount += pool.size();
205208

206209
List<IdleChannel> closedChannels = closeChannels(expiredChannels(pool, start));
207210
pool.removeAll(closedChannels);
208-
int poolClosedCount = closedChannels.size();
209-
closedCount += poolClosedCount;
211+
closedCount += closedChannels.size();
212+
if (pool.isEmpty())
213+
poolsPerKey.remove(poolKey);
210214
}
211215

212216
long duration = millisTime() - start;

0 commit comments

Comments
 (0)