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

   **[Gaojie 
Liu](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER290700)**
 opened 
**[HTTPCORE-750](https://issues.apache.org/jira/browse/HTTPCORE-750?redirect=false)**
 and commented
   
   We are using httpcore5 5.2.1 and we observed that at application startup 
time, httpclient5 could create more than 1 conn per endpoint and in some cases, 
too many connections caused OOM issue since httpclient5 creates a pair of 
input/output buffer per conn.
   
   The regression is introduced by 
[HTTPCORE-750](https://issues.apache.org/jira/browse/HTTPCORE-750), which made 
this change:
   
   
https://github.com/apache/httpcomponents-core/commit/14caf43eae407c544161c7f92329e8beb42a3534
   
    
   
   ```java
    if (poolEntry.session != null) {
                   callback.completed(poolEntry.session);
               } else {
                   poolEntry.requestQueue.add(callback);
                   if (poolEntry.sessionFuture != null && 
poolEntry.sessionFuture.isDone()) {
                       poolEntry.sessionFuture = null;
                   } 
   ```
   
   When poolEntry.sessionFuture.isDone() is true, the connection is already 
ready, but the existing logic will abandon it and create a new one, and under 
high load, this logic could create a lot of conns per endpoint, which consumes 
a lot of memory.
   
    
   
   The proposed fix:
   
   ```java
   if (poolEntry.session != null) {
                   callback.completed(poolEntry.session);
               } else {
                   poolEntry.requestQueue.add(callback);
                   if (poolEntry.sessionFuture != null && 
poolEntry.sessionFuture.isDone()) {
                       // Check whether we should recreate a new conn or not
                       try {
                           poolEntry.session = poolEntry.sessionFuture.get();
                           while (true) {
                               final FutureCallback<IOSession> pendingCallback 
= poolEntry.requestQueue.poll();
                               if (pendingCallback != null) {
                                   pendingCallback.completed(poolEntry.session);
                               } else {
                                   break;
                               }
                           }
                       } catch (final Exception e) {
                           poolEntry.sessionFuture = null;
                       }
                   } 
   ```
   
   I am planning to cut a PR for this.
   
    
   
   
   ---
   
   **Affects:** 5.2.1
   
   **Issue Links:**
   - [HTTPCORE-683](https://issues.apache.org/jira/browse/HTTPCORE-683) 
H2ConnPool bug (stuck poolEntry)
    (_**"is a clone of"**_)
   
   0 votes, 7 watchers
   


-- 
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