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 179D4C8AA for ; Sat, 22 Nov 2014 11:33:01 +0000 (UTC) Received: (qmail 98281 invoked by uid 500); 22 Nov 2014 11:33:00 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 98231 invoked by uid 500); 22 Nov 2014 11:33:00 -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 98196 invoked by uid 99); 22 Nov 2014 11:33:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2014 11:33:00 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.216.181] (HELO mail-qc0-f181.google.com) (209.85.216.181) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2014 11:32:56 +0000 Received: by mail-qc0-f181.google.com with SMTP id m20so4892553qcx.40 for ; Sat, 22 Nov 2014 03:30:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=dkoGTWRCqyA98BDFaNtFKdjk3/eb2zAdn01qj/rEYCg=; b=WJMpwq/tOMmThhdv0i2/vGmyQDjU3GmUOpUfekH375iwgwSZAezA9exTulBcvUFgmR i973AUW6uidV6+pw2KTPbsk2Z/iIMRw+VqDxQ91JmsAJ3MxDAaaWT/X79+MLjO0KyOtA 9/EMBxhjwawsVaV90tsfbZH2KtATSy0MipcIP2W9jdVdLqI8I0UFM/NPiHKN5mHFcQZF p8e/YxWm7UUqM3sgJrV95rIV/V/htoYZmBuWtheOE3uzDEhjbw1fiuPnhuqXgQUqe6FA l+jTReEffwdcCVQs+wEtDM1NHDoHs9Ej/MwPAP5igB1SAREvR8gp0gFDKsb7NnS0+CLC +wZQ== X-Gm-Message-State: ALoCoQnSYvIa2Cx6NF0zujuV9OpzP2FRjKjsMvb9ofE+tiZEpowvZAugaa++XUabI6QuWewNV2D4 MIME-Version: 1.0 X-Received: by 10.224.88.193 with SMTP id b1mr13948960qam.30.1416655819790; Sat, 22 Nov 2014 03:30:19 -0800 (PST) Received: by 10.140.106.244 with HTTP; Sat, 22 Nov 2014 03:30:19 -0800 (PST) In-Reply-To: <1416649924.27014.2.camel@apache.org> References: <231927678.3179369.1416603658212.JavaMail.yahoo@jws10626.mail.bf1.yahoo.com> <1416649924.27014.2.camel@apache.org> Date: Sat, 22 Nov 2014 06:30:19 -0500 Message-ID: Subject: Re: question on idle connections From: Sam Perman To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=001a11c2d758e875af050870e2e3 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c2d758e875af050870e2e3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable We're using 'EntityUtils.toString()' to consume the response on each request. Is that not sufficient? thanks sam On Saturday, November 22, 2014, Oleg Kalnichevski wrote: > 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 =3D httpClient.execute(httpGet); > HttpEntity entity =3D response.getEntity(); String jsonString =3D = null; > try { InputStream instream =3D 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 ar= e > > =E2=80=9Cleased=E2=80=9D (according to the PoolStats). > > > > I thought I was doing the right thing by writing an > > IdleConnectionManagerThread as recommended in the docs. This thread wil= l > > call =E2=80=9CcloseExpiredConnections=E2=80=9D and =E2=80=9CcloseIdleCo= nnections=E2=80=9D on a regular > > interval. > > > > Looking at the implementation of AbstractConnPool.closeExpired and > > AbstractConnPool.closeIdle I don=E2=80=99t understand how they work. In= our case, > > all of our connections are =E2=80=9Cleased=E2=80=9D=E2=80=A6 but these = methods only ever iterate > > and close connections that are =E2=80=9Cavailable=E2=80=9D. How do I cl= ean up leased > > connections? > > > > Iterator it =3D this.*available*.iterator(); > > while (it.hasNext()) { > > E entry =3D it.next(); > > if (entry.getUpdated() <=3D deadline) { > > entry.close(); > > RouteSpecificPool pool =3D > getPool(entry.getRoute()); > > pool.remove(entry); > > it.remove(); > > notifyPending(pool); > > } > > } > > > > thanks > > sam > > =E2=80=8B > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org > > For additional commands, e-mail: httpclient-users-help@hc.apache.org > > > --001a11c2d758e875af050870e2e3--