You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Grzegorz Jasiński (Jira)" <ji...@apache.org> on 2025/08/22 10:39:00 UTC

[jira] [Updated] (HTTPCLIENT-2389) Connection is not released after receiving "execution cancelled"

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-2389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Grzegorz Jasiński updated HTTPCLIENT-2389:
------------------------------------------
    Description: 
Hello,

I am working with httpclient async. I had encountered resource leak caused by race condition.

The execution of request was cancelled in the very end of call.
{code:java}
20250812 05:23:21.072|pool-14-thread-1|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution cancelled{code}
This caused calling InternalHttpAsyncExecRuntime method:  markConnectionNonReusable.
This method had set validDuration = null. This was done by thread pool-14-thread-1
 
In the same time "successful" path tried to release resource, it was done in PoolingAsyncClientConnectionManager release method. In this method there was verification of validDuration to not be null. Because other thread changed it to null, this check failed to release resource which is causing memory leak. This was done by thread: httpclient-dispatch-3
{code:java}
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient| ex-0105065338 message exchange successful
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient| ep-0105065112 releasing valid endpoint 
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution failed: Keep-alive time
{code}
 
 
 

stack trace for thread pool-14-thread-1:
LoggingAsyncClientExchangeHandler cancel() line 181
HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 140
HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 130
InternalHttpAsyncExecRuntime markConnectionNonReusable() line 337  <- *problematic line - set null*

 


stack trace for httpclient-dispatch-3
InternalAbstractHttpAsyncClient -->AsyncExecCallback completed() line 336
InternalHttpAsyncExecRuntime  releaseEndpoint() line 160  <-- in here *validDuration is null*
PoolingAsyncClientConnectionManager  release() line 389 <- in here *validDuration is verified if it is null, this is causing exception and is not releasing resource*
 

Full logs:
leak.log (attachment)

 

  was:
Hello,

I am working with httpclient async. I had encountered resource leak caused by race condition.

The execution of request was cancelled in the very end of call.
{code:java}
20250812 05:23:21.072|pool-14-thread-1|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution cancelled{code}
This caused calling InternalHttpAsyncExecRuntime method:  markConnectionNonReusable.
This method had set validDuration = null. This was done by thread pool-14-thread-1
 
In the same time "successful" path tried to release resource, it was done in PoolingAsyncClientConnectionManager release method. In this method there was verification of validDuration to not be null. Because other thread changed it to null, this check failed to release resource which is causing memory leak. This was done by thread: httpclient-dispatch-3
{code:java}
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient| ex-0105065338 message exchange successful
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient| ep-0105065112 releasing valid endpoint 
20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution failed: Keep-alive time
{code}
 
 
 

stack trace for thread pool-14-thread-1:
LoggingAsyncClientExchangeHandler cancel() line 181
HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 140
HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 130
InternalHttpAsyncExecRuntime markConnectionNonReusable() line 337  <- *problematic line - set null*
stack trace for httpclient-dispatch-3
InternalAbstractHttpAsyncClient -->AsyncExecCallback completed() line 336
InternalHttpAsyncExecRuntime  releaseEndpoint() line 160  <-- in here *validDuration is null*
PoolingAsyncClientConnectionManager  release() line 389 <- in here *validDuration is verified if it is null, this is causing exception and is not releasing resource*
 

Full logs:
leak.log (attachment)

 


> Connection is not released after receiving "execution cancelled"
> ----------------------------------------------------------------
>
>                 Key: HTTPCLIENT-2389
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2389
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (async)
>    Affects Versions: 5.4.1
>            Reporter: Grzegorz Jasiński
>            Priority: Major
>         Attachments: leak.log
>
>
> Hello,
> I am working with httpclient async. I had encountered resource leak caused by race condition.
> The execution of request was cancelled in the very end of call.
> {code:java}
> 20250812 05:23:21.072|pool-14-thread-1|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution cancelled{code}
> This caused calling InternalHttpAsyncExecRuntime method:  markConnectionNonReusable.
> This method had set validDuration = null. This was done by thread pool-14-thread-1
>  
> In the same time "successful" path tried to release resource, it was done in PoolingAsyncClientConnectionManager release method. In this method there was verification of validDuration to not be null. Because other thread changed it to null, this check failed to release resource which is causing memory leak. This was done by thread: httpclient-dispatch-3
> {code:java}
> 20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient| ex-0105065338 message exchange successful
> 20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient| ep-0105065112 releasing valid endpoint 
> 20250812 05:23:21.072|httpclient-dispatch-3|DEBUG|org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec| ex-0105065338: execution failed: Keep-alive time
> {code}
>  
>  
>  
> stack trace for thread pool-14-thread-1:
> LoggingAsyncClientExchangeHandler cancel() line 181
> HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 140
> HttpAsyncMainClientExec --> AsyncClientExchangeHandler cancel()  line 130
> InternalHttpAsyncExecRuntime markConnectionNonReusable() line 337  <- *problematic line - set null*
>  
> stack trace for httpclient-dispatch-3
> InternalAbstractHttpAsyncClient -->AsyncExecCallback completed() line 336
> InternalHttpAsyncExecRuntime  releaseEndpoint() line 160  <-- in here *validDuration is null*
> PoolingAsyncClientConnectionManager  release() line 389 <- in here *validDuration is verified if it is null, this is causing exception and is not releasing resource*
>  
> Full logs:
> leak.log (attachment)
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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