[
https://issues.apache.org/jira/browse/HTTPCORE-490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oleg Kalnichevski resolved HTTPCORE-490.
----------------------------------------
Resolution: Fixed
Fixed in 4.4.x branch. Master (5.x) is not affected.
Oleg
> 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: [email protected]
For additional commands, e-mail: [email protected]