jira-importer opened a new issue, #1228: URL: https://github.com/apache/httpcomponents-core/issues/1228
**[Saksham](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=saksham2405)** opened **[HTTPCORE-675](https://issues.apache.org/jira/browse/HTTPCORE-675?redirect=false)** and commented We are using **CloseableHttpClient** with **PoolingHttpClientConnectionManager,** following is the configuration: ```java RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000) .setConnectionRequestTimeout(1000) .setSocketTimeout(1000) .build(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(100); connectionManager.setDefaultMaxPerRoute(100); this.httpClient = HttpClients.custom() .setDefaultRequestConfig(requestConfig) .setConnectionManager(connectionManager) .build(); ``` Now when we are not consuming the response entity and just relying on closeableHttpResponse to release the resources, we end up with 25K connections in CLOSE_WAIT state with just over 400RPS to the system. Due this system runs out of resources very quickly and requests start failing. Problem Snippet: ```java try (CloseableHttpResponse response = this.httpClient.execute(httpGet)){ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toByteArray(response.getEntity()); } else { if (response.getStatusLine().getStatusCode() >= 500) { throw new RemoteCallFailException(); } } } catch (IOException e) { logger.error("Remote db read request failed [{}]", e.getMessage(), e); throw new RemoteCallFailException(); } ``` After using **EntityUtils.toByteArray(response.getEntity()) in the else block** of above code connections are properly getting released and reused in subsequent requests. Working Snippet: ```java try (CloseableHttpResponse response = this.httpClient.execute(httpGet)) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return EntityUtils.toByteArray(response.getEntity()); } else { // Consuming stream to release connection EntityUtils.toByteArray(response.getEntity()); if (response.getStatusLine().getStatusCode() >= 500) { throw new RemoteCallFailException(); } } } catch (IOException e) { logger.error("Remote db read request failed [{}]", e.getMessage(), e); throw new RemoteCallFailException(); } ``` Can someone please point why releasing of connection is not automatically done by closeablehttpResponse.close() ? ( Or maybe point to something wrong in the code) MVN dependency used for same: \<dependency> \<groupId>org.apache.httpcomponents\</groupId> \<artifactId>httpclient\</artifactId> \<version>4.3.3\</version> \</dependency> --- No further details from [HTTPCORE-675](https://issues.apache.org/jira/browse/HTTPCORE-675?redirect=false) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
