Uploaded image for project: 'HttpComponents HttpAsyncClient'
  1. HttpComponents HttpAsyncClient
  2. HTTPASYNC-3

Async SessionPool does not correctly handle expired I/O sessions

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 4.0-alpha1
    • Fix Version/s: 4.0-alpha2
    • Labels:
      None

      Description

      here is an example code to use the HTTP AsyncClient and seeing an exception. Please also let me know how to deal with this issue,

      /*

      • To change this template, choose Tools | Templates
      • and open the template in the editor.
        */
        package httpanalysis.apache;

      import java.util.concurrent.CountDownLatch;
      import java.util.concurrent.Future;
      import java.util.concurrent.TimeUnit;
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import org.apache.http.HttpHost;

      import org.apache.http.HttpResponse;
      import org.apache.http.client.methods.HttpGet;
      import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
      import org.apache.http.impl.nio.conn.PoolingClientConnectionManager;
      import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
      import org.apache.http.nio.client.HttpAsyncClient;
      import org.apache.http.nio.conn.scheme.Scheme;
      import org.apache.http.nio.conn.scheme.SchemeRegistry;
      import org.apache.http.nio.reactor.ConnectingIOReactor;
      import org.apache.http.nio.reactor.IOReactorException;
      import org.apache.http.params.BasicHttpParams;
      import org.apache.http.params.CoreConnectionPNames;

      /**
      *

      • @author lokesh
        */
        public class HttpAnalysis {

      PoolingClientConnectionManager poolManager;
      HttpAsyncClient httpclient = null;
      private PoolingClientConnectionManager sessionManager;

      /**

      • @param args the command line arguments
        */
        public static void main(String[] args) { HttpAnalysis analysis = new HttpAnalysis(); analysis.process(); }

      public HttpAnalysis() {
      try

      { BasicHttpParams basicHttpParams = new BasicHttpParams(); basicHttpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1); basicHttpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 2); basicHttpParams.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 2 * 1024); basicHttpParams.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); basicHttpParams.setParameter(CoreConnectionPNames.SO_REUSEADDR, false); ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, basicHttpParams); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, null)); this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry, 5, TimeUnit.MINUTES); sessionManager.setTotalMax(50); sessionManager.setDefaultMaxPerHost(25); this.httpclient = new DefaultHttpAsyncClient(ioReactor, sessionManager,basicHttpParams); }

      catch (IOReactorException ex)

      { Logger.getLogger(HttpAnalysis.class.getName()).log(Level.SEVERE, null, ex); }
      }

      private void process() {
      try {
      int numRequests = 10000;
      httpclient.start();
      long startTime = System.currentTimeMillis();
      final CountDownLatch countDownLatch = new CountDownLatch(numRequests);
      for (int i = 0; i < numRequests; i++) {
      HttpGet request = new HttpGet("http://hc.apache.org/");
      Future<HttpResponse> future = httpclient.execute(request, new HttpCallback(this, countDownLatch));
      if(future == null){ countDownLatch.countDown(); }
      System.out.println("Request number = " + i);
      //sessionManager.closeExpiredConnections();
      }
      countDownLatch.await();
      System.out.println((System.currentTimeMillis() - startTime));
      System.exit(1);
      } catch (Exception ex) { Logger.getLogger(HttpAnalysis.class.getName()).log(Level.SEVERE, null, ex); }

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              lokeshhctm Lokesh
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1m
                1m
                Remaining:
                Remaining Estimate - 1m
                1m
                Logged:
                Time Spent - Not Specified
                Not Specified