Skip to content

Commit 7716af5

Browse files
author
Stephane Landelle
committed
Fix NPE caused by AsyncHttpClient#676, close AsyncHttpClient#678
1 parent d0776dc commit 7716af5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/main/java/com/ning/http/client/providers/netty/channel/pool/DefaultChannelPool.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.ArrayList;
3030
import java.util.Collections;
3131
import java.util.List;
32-
import java.util.Map;
3332
import java.util.concurrent.ConcurrentHashMap;
3433
import java.util.concurrent.ConcurrentLinkedQueue;
3534
import java.util.concurrent.TimeUnit;
@@ -195,21 +194,21 @@ public void run(Timeout timeout) throws Exception {
195194
int closedCount = 0;
196195
int totalCount = 0;
197196

198-
for (Map.Entry<String, ConcurrentLinkedQueue<IdleChannel>> entry : poolsPerKey.entrySet()) {
199-
200-
String poolKey = entry.getKey();
201-
ConcurrentLinkedQueue<IdleChannel> pool = entry.getValue();
197+
for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) {
202198

203199
// store in intermediate unsynchronized lists to minimize the impact on the ConcurrentLinkedQueue
204200
if (LOGGER.isDebugEnabled())
205201
totalCount += pool.size();
206202

207203
List<IdleChannel> closedChannels = closeChannels(expiredChannels(pool, start));
208204

209-
pool.removeAll(closedChannels);
210-
closedCount += closedChannels.size();
211-
if (pool.isEmpty())
212-
poolsPerKey.remove(poolKey);
205+
if (!closedChannels.isEmpty()) {
206+
for (IdleChannel closedChannel : closedChannels)
207+
channelId2Creation.remove(closedChannel.channel.getId());
208+
209+
pool.removeAll(closedChannels);
210+
closedCount += closedChannels.size();
211+
}
213212
}
214213

215214
long duration = millisTime() - start;

0 commit comments

Comments
 (0)