Closing Idle and Expired connection is application only when stream associated with Connection is closed, otherwise connections are not considered idle. Looks like there is leak in connections at your side. Below code snippet shows one example on how to close the stream in a guaranteed fashion. HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); String jsonString = null; try { InputStream instream = entity.getContent(); /* do your processing with the stream */ } finally { EntityUtils.consumeQuietly(entity); } Jaikit
On Friday, November 21, 2014 12:48 PM, Sam Perman <s...@permans.com> wrote: Hello We have had a persistent issue in production where after a few days our PoolingClientConnectionManager becomes unusable because there are no available connections. It turns out all of the available connections are “leased” (according to the PoolStats). I thought I was doing the right thing by writing an IdleConnectionManagerThread as recommended in the docs. This thread will call “closeExpiredConnections” and “closeIdleConnections” on a regular interval. Looking at the implementation of AbstractConnPool.closeExpired and AbstractConnPool.closeIdle I don’t understand how they work. In our case, all of our connections are “leased”… but these methods only ever iterate and close connections that are “available”. How do I clean up leased connections? Iterator<E> it = this.*available*.iterator(); while (it.hasNext()) { E entry = it.next(); if (entry.getUpdated() <= deadline) { entry.close(); RouteSpecificPool<T, C, E> pool = getPool(entry.getRoute()); pool.remove(entry); it.remove(); notifyPending(pool); } } thanks sam