Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A8991C6EF for ; Sat, 22 Nov 2014 09:52:08 +0000 (UTC) Received: (qmail 35793 invoked by uid 500); 22 Nov 2014 09:52:08 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 35745 invoked by uid 500); 22 Nov 2014 09:52:08 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 35734 invoked by uid 99); 22 Nov 2014 09:52:08 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2014 09:52:08 +0000 Received: from ubuntu (77-57-180-223.dclient.hispeed.ch [77.57.180.223]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id C95C11A0287 for ; Sat, 22 Nov 2014 09:52:02 +0000 (UTC) Message-ID: <1416649924.27014.2.camel@apache.org> Subject: Re: question on idle connections From: Oleg Kalnichevski To: HttpClient User Discussion Date: Sat, 22 Nov 2014 10:52:04 +0100 In-Reply-To: <231927678.3179369.1416603658212.JavaMail.yahoo@jws10626.mail.bf1.yahoo.com> References: <231927678.3179369.1416603658212.JavaMail.yahoo@jws10626.mail.bf1.yahoo.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.7-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit On Fri, 2014-11-21 at 21:00 +0000, Jaikit Savla wrote: > 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 wrote: > > Jaikit is absolutely right. This section of the HttpClient tutorial may also be of help: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e145 Oleg > 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 it = this.*available*.iterator(); > while (it.hasNext()) { > E entry = it.next(); > if (entry.getUpdated() <= deadline) { > entry.close(); > RouteSpecificPool pool = getPool(entry.getRoute()); > pool.remove(entry); > it.remove(); > notifyPending(pool); > } > } > > thanks > sam > ​ > > --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org