wenqi.huang created HTTPASYNC-123:
-------------------------------------
Summary: concurrent bug when invoke future.cancel
Key: HTTPASYNC-123
URL: https://issues.apache.org/jira/browse/HTTPASYNC-123
Project: HttpComponents HttpAsyncClient
Issue Type: Bug
Affects Versions: 4.1.3
Reporter: wenqi.huang
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]