You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2019/02/01 08:22:00 UTC

[jira] [Commented] (HTTPCORE-567) Connection leak when aborting httpRequest after connection leasing

    [ https://issues.apache.org/jira/browse/HTTPCORE-567?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16758082#comment-16758082 ] 

ASF subversion and git services commented on HTTPCORE-567:
----------------------------------------------------------

Commit 9b5b641cd06dd883d0b72eae8a71e8a71f52729b in httpcomponents-core's branch refs/heads/4.4.x from Oleg Kalnichevski
[ https://gitbox.apache.org/repos/asf?p=httpcomponents-core.git;h=9b5b641 ]

HTTPCORE-567: fixed race condition that may cause a connection leak when the connection lease request is cancelled from another thread.


> Connection leak when aborting httpRequest after connection leasing
> ------------------------------------------------------------------
>
>                 Key: HTTPCORE-567
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-567
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>    Affects Versions: 4.4.11
>            Reporter: Zoe Wang
>            Priority: Major
>
> This is a follow up on https://issues.apache.org/jira/browse/HTTPCLIENT-1958. 
> The leaking thread interrupt flag is fixed but we noticed that there's an edge case when a request gets aborted right after a new connection is leased, that connection will never get re-used and closed. 
>  
> From the [source code|https://github.com/apache/httpcomponents-client/blob/4.5.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java#L305], looks like the edge case that needs to be handled is "if (entry != null && future.isCancelled())"
> Code to reproduce:
> {code:java}
> ScheduledExecutorService scheduledExecutorService =           Executors.newScheduledThreadPool(1);
> PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
> CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(poolingHttpClientConnectionManager).build();
> try {
> HttpGet httpGet = new HttpGet("http://somehost");
> scheduledExecutorService.schedule(httpGet::abort, 40, TimeUnit.MILLISECONDS);
> CloseableHttpResponse response = httpclient.execute(httpGet);
> HttpEntity entity = response.getEntity();
> EntityUtils.consume(entity);
> } catch (Exception e) {
>     e.printStackTrace();
> } finally {
> scheduledExecutorService.shutdown();
> }
> System.out.println(poolingHttpClientConnectionManager.getTotalStats());
> {code}
> The printed out log was: [leased: 1; pending: 0; available: 0; max: 20]
> Note that you might need to change the abort time to reproduce the issue.
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org