From 221c1550600192d1b5f4ebf91e6c1ac8a56a9546 Mon Sep 17 00:00:00 2001 From: "yihua.huang" Date: Sat, 18 Mar 2017 11:15:36 +0800 Subject: [PATCH] move release connection before return proxy #396 --- .../webmagic/downloader/HttpClientDownloader.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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); - } } }