Skip to content

Commit db341f1

Browse files
author
Stephane Landelle
committed
Fix DefaultChannelPool.closeChannels, close AsyncHttpClient#804
1 parent 72b395e commit db341f1

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ private boolean isChannelCloseable(Channel channel) {
151151
Object attribute = Channels.getAttribute(channel);
152152
if (attribute instanceof NettyResponseFuture) {
153153
NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute;
154-
if (!future.isDone())
154+
if (!future.isDone()) {
155155
LOGGER.error("Future not in appropriate state %s, not closing", future);
156+
return false;
157+
}
156158
}
157159
return true;
158160
}
@@ -163,19 +165,19 @@ private final List<IdleChannel> closeChannels(List<IdleChannel> candidates) {
163165
List<IdleChannel> closedChannels = null;
164166
for (int i = 0; i < candidates.size(); i++) {
165167
IdleChannel idleChannel = candidates.get(i);
166-
if (!isChannelCloseable(idleChannel.channel))
167-
if (closedChannels == null) {
168-
// first non closeable to be skipped, copy all previously skipped closeable channels
169-
closedChannels = new ArrayList<IdleChannel>(candidates.size());
170-
for (int j = 0; j < i; j++)
171-
closedChannels.add(candidates.get(j));
172-
} else {
173-
LOGGER.debug("Closing Idle Channel {}", idleChannel.channel);
174-
close(idleChannel.channel);
175-
if (closedChannels != null) {
176-
closedChannels.add(idleChannel);
177-
}
168+
if (isChannelCloseable(idleChannel.channel)) {
169+
LOGGER.debug("Closing Idle Channel {}", idleChannel.channel);
170+
close(idleChannel.channel);
171+
if (closedChannels != null) {
172+
closedChannels.add(idleChannel);
178173
}
174+
175+
} else if (closedChannels == null) {
176+
// first non closeable to be skipped, copy all previously skipped closeable channels
177+
closedChannels = new ArrayList<IdleChannel>(candidates.size());
178+
for (int j = 0; j < i; j++)
179+
closedChannels.add(candidates.get(j));
180+
}
179181
}
180182

181183
return closedChannels != null ? closedChannels : candidates;

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ private boolean isChannelCloseable(Channel channel) {
155155
Object attribute = Channels.getAttribute(channel);
156156
if (attribute instanceof NettyResponseFuture) {
157157
NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute;
158-
if (!future.isDone())
158+
if (!future.isDone()) {
159159
LOGGER.error("Future not in appropriate state %s, not closing", future);
160+
return false;
161+
}
160162
}
161163
return true;
162164
}
@@ -168,17 +170,18 @@ private final List<IdleChannel> closeChannels(List<IdleChannel> candidates) {
168170
for (int i = 0; i < candidates.size(); i++) {
169171
IdleChannel idleChannel = candidates.get(i);
170172
if (!isChannelCloseable(idleChannel.channel))
171-
if (closedChannels == null) {
172-
// first non closeable to be skipped, copy all previously skipped closeable channels
173-
closedChannels = new ArrayList<IdleChannel>(candidates.size());
174-
for (int j = 0; j < i; j++)
175-
closedChannels.add(candidates.get(j));
176-
} else {
173+
if (isChannelCloseable(idleChannel.channel)) {
177174
LOGGER.debug("Closing Idle Channel {}", idleChannel.channel);
178175
close(idleChannel.channel);
179176
if (closedChannels != null) {
180177
closedChannels.add(idleChannel);
181178
}
179+
180+
} else if (closedChannels == null) {
181+
// first non closeable to be skipped, copy all previously skipped closeable channels
182+
closedChannels = new ArrayList<IdleChannel>(candidates.size());
183+
for (int j = 0; j < i; j++)
184+
closedChannels.add(candidates.get(j));
182185
}
183186
}
184187

0 commit comments

Comments
 (0)