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

   
**[wenqi.huang](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=after_sss)**
 opened 
**[HTTPCORE-490](https://issues.apache.org/jira/browse/HTTPCORE-490?redirect=false)**
 and commented
   
   The following code has a bug that the third http invoke will never respond. 
pay attention to the parameters setted in the code like 
socketTimeout,maxConnPerRoute,maxConnTotal, etc. and the url invoked must block 
for 5 seconds at server side(in other worlds, sleep for 5 seconds.)
   
   ```java
   
   public class AsyncHttpClientTest {
       public static void main(String[] args) throws InterruptedException {
           //please attention to the socketTimeout,maxConnPerRoute,maxConnTotal
           CloseableHttpAsyncClient c = HttpAsyncClientBuilder.create()
                   
.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(4000).build())
                   .setMaxConnPerRoute(1).setMaxConnTotal(1).build();
           c.start();
   
           //this url will block for 5 seconds at server side.
           HttpGet httpGet = new 
HttpGet("http://localhost:8778/someUrlWillBlockForFiveSecondsAtServerSide";);
   
           Future f1 = execute(httpGet, c);
           Future f2 = execute(httpGet, c);
   
           //this http invoke will never success or fail.
           Future f3 = execute(httpGet, c);
   
           System.out.println("begin");
           Thread.sleep(1000);
           f1.cancel(true);
           f2.cancel(true);
       }
   
       private static Future execute(HttpGet httpGet, CloseableHttpAsyncClient 
c){
           return c.execute(httpGet, new FutureCallback<HttpResponse>() {
               @Override
               public void completed(HttpResponse result) {
                   String ret = null;
                   try {
                       ret = IOUtils.toString(result.getEntity().getContent());
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
                   System.out.println("completed:"+ret);
               }
   
               @Override
               public void failed(Exception ex) {
                   System.out.println("failed");
                   ex.printStackTrace();
               }
   
               @Override
               public void cancelled() {
                   System.out.println("cancelled");
               }
           });
       }
   }
   ```
   
   
   
   ---
   
   **Affects:** 4.4.7
   
   **Issue Links:**
   - [HTTPASYNC-116](https://issues.apache.org/jira/browse/HTTPASYNC-116) 
Cancelling the Future returned by CloseableHttpAsyncClient should release all 
resources allocated to the request that created it.
   
   


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