Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 87566 invoked from network); 9 Feb 2005 22:50:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 9 Feb 2005 22:50:58 -0000 Received: (qmail 58064 invoked by uid 500); 9 Feb 2005 22:50:57 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 58049 invoked by uid 500); 9 Feb 2005 22:50:57 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 58036 invoked by uid 99); 9 Feb 2005 22:50:57 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from mail15.bluewin.ch (HELO mail15.bluewin.ch) (195.186.18.63) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 09 Feb 2005 14:50:55 -0800 Received: from xbox.localdomain (81.62.39.240) by mail15.bluewin.ch (Bluewin AG 7.0.035) id 41DE9B9E002D12A6 for httpclient-user@jakarta.apache.org; Wed, 9 Feb 2005 22:50:53 +0000 Received: from 192.168.0.2 (unknown [192.168.0.2]) by xbox.localdomain (Postfix) with ESMTP id 422B6B6ECB for ; Wed, 9 Feb 2005 23:50:53 +0100 (CET) Subject: RE: Socket Exception From: Oleg Kalnichevski To: HttpClient User Discussion In-Reply-To: <81EA33D2D997D948BC14AC780BD495847B7D1F@exchange01.sccorp.com> References: <81EA33D2D997D948BC14AC780BD495847B7D1F@exchange01.sccorp.com> Content-Type: text/plain Date: Wed, 09 Feb 2005 23:50:52 +0100 Message-Id: <1107989452.6625.45.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Prasad, First of all, by HTTP spec both the client and the server may drop connection at any point of time without giving a prior warning of any sort. HttpClient usually keeps the connection open indefinitely if the connection is reusable (HTTP/1.1 connection or HTTP/1.0 connection explicitly marked as reusable with 'connection:keep-alive'). The server, however, may choose to close this connection after a certain period of inactivity, thus rendering the connection 'stale' on the client side. HttpClient in its turn has no way of knowing if the connection is still valid (we do perform a so called 'stale' connection check but it cannot be 100% reliable). Next time the stale connection is used, the request fails with the SocketException You have several options (1) do not keep persistent connections open indefinitely on the client side and close them after a certain period of inactivity (2) retry the failed request PROVIDED the request is idempotent. Oleg On Wed, 2005-02-09 at 15:29 -0700, Prasad Sethumadhavan wrote: > Hi Oleg, > Thanks for the reply. I have added a custom retry handler now. However > my main concern is why this exception is happening in the first place. > If I use the http client without any major break (even heavy load tests > with 100-200 clients works great). However if I use the HttpClient > sparsely like once every 3 minutes or so why am I getting this > exception. Is this happening because the http client is resuing > connections and the connection was closed by the server? If so then why > am I getting a "recv failed" consistently? > I guess this use case of using the http client sparsely is very common. > So is it a configuration problem on my part? Please help me out. > > Thanks > Prasad > > -----Original Message----- > From: Oleg Kalnichevski [mailto:olegk@apache.org] > Sent: Wednesday, February 09, 2005 2:25 PM > To: HttpClient User Discussion > Subject: Re: Socket Exception > > Prasad, > > See handling.html#HTTP%20transport%20safety> > > Oleg > > On Tue, 2005-02-08 at 16:43 -0700, Prasad Sethumadhavan wrote: > > Hi, > > I am getting a SocketException if I use a HttpClient instance after a > > gap of 3 minutes. > > > > //Initialization > > > > MultiThreadedHttpConnectionManager manager = > > new MultiThreadedHttpConnectionManager(); > > manager.getParams().setStaleCheckingEnabled(true); > > manager.getParams().setDefaultMaxConnectionsPerHost( > > config.getMaxHttpConnections()); > > manager.getParams().setMaxTotalConnections( > > config.getMaxHttpConnections()); > > manager.getParams().setConnectionTimeout( > > config.getDefaultConnectionTimeout()); > > > > Httpclient httpclient = new HttpClient(manager); > > httpclient.getParams().setCookiePolicy( > > CookiePolicy.BROWSER_COMPATIBILITY); > > > > I create a new method to a URL and execute it using > > httpClient.executeMethod(). I then sleep for 180 seconds and then > > access the same URL using a newly created method and I am getting the > > following exception. I can reproduce this consistently. > > > > Please let me know if there is some property that I need to set to > > avoid this problem. Also, in my application, requests can come at any > > time and hence I should be able to use the httpclient after any > interval. > > > > Thanks in advance > > Prasad > > > > //Stack Trace > > > > java.net.SocketException: Software caused connection abort: recv > failed > > at java.net.SocketInputStream.socketRead0(Native Method) > > at java.net.SocketInputStream.read(SocketInputStream.java:129) > > at > > java.io.BufferedInputStream.fill(BufferedInputStream.java:218) > > at > > java.io.BufferedInputStream.read(BufferedInputStream.java:235) > > at > > > org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:76) > > at > > org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:104) > > at > > org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.j > > av > > a:1112) > > at > > org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpC > > on > > nectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1379) > > at > > org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethod > > Ba > > se.java:1825) > > at > > org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBa > > se > > .java:1588) > > at > > org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.ja > > va > > :999) > > at > > org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Http > > Me > > thodDirector.java:382) > > at > > org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMet > > ho > > dDirector.java:168) > > at > > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java > > :3 > > 93) > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: > > httpclient-user-help@jakarta.apache.org > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org