httpclient exception "org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection" httpclient exception "org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection" java java

httpclient exception "org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection"


I had the same problem and I found the fix.This timeout is because of a connection leak. In my case, I'm using httpDelete method and not consuming the response. Instead, I'm checking the status of the response.

The fix is, the response entity needs to be consumed. In order to ensure the proper release of system resources, one must close the content stream associated with the entity.

So I used EntityUtils.consumeQuietly(response.getEntity()); which ensures that the entity content is fully consumed and the content stream, if exists, is closed.


I have fixed it! add mPost.releaseConnection() in finally blocks.

 try { } catch (Exception e) { } finally {  mPost.releaseConnection(); }

DO update package org.apache.httpcomponents to 4.2.1


Just put the line where you are getting your response inside try-with-resources and use CloseableHttpResponse instead of HttpResponse like this:

try(final CloseableHttpResponse mHttpResponse = client.execute(mPost);){ System.out.println("HttpClientTest  ---> get response"); ....remainder code

The mHttpResponse object will be auto consumed and closed for you

Hope this helps!