-
Bug
-
Resolution: Done
-
Major
-
1.2.1.GA
-
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.