Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-567

Connection leak when aborting httpRequest after connection leasing

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.4.11
    • Fix Version/s: 4.4.12
    • Component/s: None
    • Labels:
      None

      Description

      This is a follow up on https://issues.apache.org/jira/browse/HTTPCLIENT-1958

      The leaking thread interrupt flag is fixed but we noticed that there's an edge case when a request gets aborted right after a new connection is leased, that connection will never get re-used and closed. 

       

      From the source code, looks like the edge case that needs to be handled is "if (entry != null && future.isCancelled())"

      Code to reproduce:

      ScheduledExecutorService scheduledExecutorService =           Executors.newScheduledThreadPool(1);
      PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
      
      CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(poolingHttpClientConnectionManager).build();
      
      try {
      HttpGet httpGet = new HttpGet("http://somehost");
      scheduledExecutorService.schedule(httpGet::abort, 40, TimeUnit.MILLISECONDS);
      CloseableHttpResponse response = httpclient.execute(httpGet);
      
      HttpEntity entity = response.getEntity();
      EntityUtils.consume(entity);
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
      scheduledExecutorService.shutdown();
      }
      
      System.out.println(poolingHttpClientConnectionManager.getTotalStats());
      

      The printed out log was: [leased: 1; pending: 0; available: 0; max: 20]

      Note that you might need to change the abort time to reproduce the issue.

       

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Zoe Wang Zoe Wang

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment