Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-362

Client connection leak on HTTP error response

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.0-beta-2
    • 1.2.1.GA
    • jaxrs
    • None

      When HTTP client gets error response (4xx or 5xx), connection is not released leading to connection leak. Example with ApacheHttpClient4Executor (but probably other are also affected):

      ConnectionLeak.java
      final SchemeRegistry schemeRegistry = new SchemeRegistry();
      	    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
      
      	    final HttpParams params = new BasicHttpParams();
      	    ConnManagerParams.setMaxTotalConnections(params, 2);
      	    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(2));
      
      	    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
      		
      		HttpClient httpClient = new DefaultHttpClient(manager, new BasicHttpParams());
      		TestClient client = ProxyFactory.create(TestClient.class,
      				"http://localhost", new ApacheHttpClient4Executor(httpClient));
      		
      		for(int i =0; i < 10; i++) {
      			try {
      				client.method();
      			} catch(ClientResponseFailure e) {
      				e.printStackTrace();
      			}
      		}
      

      where TestClient is any client interface. Above program will hang after second connection. Please note that this will only occur if the server actually returns 4xx or 5xx response, in case there is no server running on localhost, this bug will not manifest.

            patriot1burke@gmail.com Bill Burke (Inactive)
            rraptorr Janusz Dziemidowicz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: