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:[EMAIL PROTECTED] > Sent: Wednesday, February 09, 2005 2:25 PM > To: HttpClient User Discussion > Subject: Re: Socket Exception > > Prasad, > > See <http://jakarta.apache.org/commons/httpclient/3.0/exception- > 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: [EMAIL PROTECTED] > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
