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

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

Commit 4bf39ed9eab5d2324b73a42583b8b21add917084 in httpcomponents-core's branch 
refs/heads/4.4.x from [~garydgregory]
[ https://git-wip-us.apache.org/repos/asf?p=httpcomponents-core.git;h=4bf39ed ]

* HTTPCORE-490: session requests do not get cancelled correctly if the
associated HTTP response fututes get cancelled
  Contributed by Oleg Kalnichevski <olegk at apache.org>


> concurrent bug when invoke future.cancel
> ----------------------------------------
>
>                 Key: HTTPCORE-490
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-490
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>    Affects Versions: 4.4.7
>            Reporter: wenqi.huang
>            Assignee: Oleg Kalnichevski
>             Fix For: 4.4.8
>
>
> 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.)
>  
> {code: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");
>             }
>         });
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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

Reply via email to