jira-importer opened a new issue, #1095:
URL: https://github.com/apache/httpcomponents-core/issues/1095

   **[Linton 
Miller](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=linton.miller)**
 opened 
**[HTTPCORE-584](https://issues.apache.org/jira/browse/HTTPCORE-584?redirect=false)**
 and commented
   
   Iterating over connections in a LaxConnPool can cause unexpected connection 
exceptions; for example, calling the closeIdle or closeExpired methods at the 
same time as threads are requesting connections from the pool.
   
   This is demonstrated by the attached test class, which creates a LaxConnPool 
for a PoolingHttpClientConnectionManager and then uses that to execute a number 
of concurrent requests, sleeps a bit, then re-executes concurrent requests at 
the same time as closing idle connections in the pool. Being a threading bug, 
it's not a guaranteed fail every time, but within a few runs, the test code 
will normally get at least one request thread that fails. e.g
   
   ```
   Thread req-000000AB request failed!
   org.apache.hc.core5.http.ConnectionClosedException: Connection is closed
           at 
org.apache.hc.core5.http.impl.io.BHttpConnectionBase.ensureOpen(BHttpConnectionBase.java:98)
           at 
org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:186)
           at 
org.apache.hc.core5.http.impl.io.HttpRequestExecutor.execute(HttpRequestExecutor.java:181)
           at 
org.apache.hc.core5.http.impl.io.HttpRequestExecutor.execute(HttpRequestExecutor.java:224)
           at 
org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$InternalConnectionEndpoint.execute(PoolingHttpClientConnectionManager.java:596)
           at 
org.apache.hc.client5.http.impl.classic.InternalExecRuntime.execute(InternalExecRuntime.java:220)
           at 
org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:175)
   ...
           at 
org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:77)
           at 
org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:102)
           at 
LaxConnPoolThreadingTest$2.executeReq(LaxConnPoolThreadingTest.java:69)
           at LaxConnPoolThreadingTest$2.run(LaxConnPoolThreadingTest.java:58)
   ```
   
   or
   
    
   
   ```
   Thread req-00000179 request failed!
   java.lang.IllegalStateException: Endpoint is not connected
           at org.apache.hc.core5.util.Asserts.check(Asserts.java:38)
           at 
org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$InternalConnectionEndpoint.getValidatedPoolEntry(PoolingHttpClientConnectionManager.java:548)
           at 
org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager$InternalConnectionEndpoint.execute(PoolingHttpClientConnectionManager.java:592)
   ...
   ```
   
   There may also be recoverable I/O exceptions logged:
   
   ```
   2019-07-24 09:17:27,488 INFO  
[org.apache.hc.client5.http.impl.classic.RetryExec] Recoverable I/O exception 
(java.net.SocketException) caught when processing request to 
{}->http://httpbin.org:80
   ```
   
    
   
   This appear to be because the iteration methods of LaxConnPool are not 
thread-safe. Though their access to the internal queue structures are protected 
by the queues being ConcurrentLinkedDeque, the iteration provides the means for 
the same pool entry to be accessed on multiple threads at once because there is 
no locking or concurrency control on the individual pool entries as the 
callback is executed through enumAvailable or enumLeased.
   
    
   
    
   
    
   
   
   ---
   
   **Affects:** 5.0-beta8
   
   **Attachments:**
   - 
[LaxConnPoolThreadingTest.java](https://issues.apache.org/jira/secure/attachment/12975564/LaxConnPoolThreadingTest.java)
 (_3.17 kB_)
   - 
[LaxConnPoolThreadingTest2.java](https://issues.apache.org/jira/secure/attachment/12975929/LaxConnPoolThreadingTest2.java)
 (_7.64 kB_)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to