diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java b/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java index 952a750..fa907a1 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java @@ -113,19 +113,15 @@ public class HttpClientDownloader extends AbstractDownloader { onError(request); return null; } finally { + if (httpResponse != null) { + //ensure the connection is released back to pool + EntityUtils.consumeQuietly(httpResponse.getEntity()); + } request.putExtra(Request.STATUS_CODE, statusCode); if (site != null && site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) { site.returnHttpProxyToPool((HttpHost) request.getExtra(Request.PROXY), (Integer) request .getExtra(Request.STATUS_CODE)); } - try { - if (httpResponse != null) { - //ensure the connection is released back to pool - EntityUtils.consume(httpResponse.getEntity()); - } - } catch (IOException e) { - logger.warn("close response fail", e); - } } }