Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
4.5.5, 4.5.6
-
None
Description
When calling HttpRequestBase#abort during the leasing connection phase, the thread is being interrupted and `RequestAbortedException` will be thrown.
It is an unexpected behavior that aborting the http request would cause the interrupt flag to be set on the caller thread.
Here is what happened looking from the source code of 4.5.5,
- Aborting the request invokes future.cancel(true) and it throws InterruptedException https://github.com/apache/httpcomponents-client/blob/4.5.5/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java#L272
- InterruptedException is caught in MainClientExec and then it re-interrupts the thread and throws RequestAbortedException
The second step is expected and the first step seems to be the root cause. Should we use `future.cancel(false)` instead as it causes the side effect for a simple httprequest#abort to interrupt the caller's thread?
Code to reproduce:
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
try (
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(poolingHttpClientConnectionManager).build())
catch (Exception e)
{ e.printStackTrace(); }finally
{ scheduledExecutorService.shutdown(); }System.out.println("Interrupted ?" + Thread.currentThread().isInterrupted());