You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "De Backer Frederik (DBB)" <Fr...@dexia.com> on 2012/01/11 07:50:02 UTC

java.net.SocketTimeoutException: Read timed out

Hello everyone,

I am using HttpClient 4.1.2 inside a servlet deployed in a Websphere
application server. The JRE version is 1.6.0.

I am using this httpclient to connect to google maps api. This HTTP
connection goes via a proxy server. Most of the time my code works ok.
However from time to time I receive the exception below (my read timeout
is set to 60 seconds).

java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
~[na:1.6.0]
        at java.net.SocketInputStream.read(SocketInputStream.java:140)
~[na:1.6.0]
        at com.ibm.jsse2.a.a(a.java:203) ~[na:6.0 build_20110301]
        at com.ibm.jsse2.a.a(a.java:80) ~[na:6.0 build_20110301]
        at com.ibm.jsse2.tc.a(tc.java:549) ~[na:6.0 build_20110301]
        at com.ibm.jsse2.tc.g(tc.java:25) ~[na:6.0 build_20110301]
        at com.ibm.jsse2.tc.a(tc.java:407) ~[na:6.0 build_20110301]
        at com.ibm.jsse2.j.write(j.java:11) ~[na:6.0 build_20110301]
        at
org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(Abstract
SessionOutputBuffer.java:131) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.io.AbstractSessionOutputBuffer.flush(AbstractSessio
nOutputBuffer.java:138) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.AbstractHttpClientConnection.doFlush(AbstractHttpCl
ientConnection.java:270) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.AbstractHttpClientConnection.flush(AbstractHttpClie
ntConnection.java:275) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.conn.AbstractClientConnAdapter.flush(AbstractClient
ConnAdapter.java:197) ~[httpclient-4.1.2.jar:4.1.2]
        at
org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestEx
ecutor.java:258) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor
.java:123) ~[httpcore-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultReq
uestDirector.java:645) ~[httpclient-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultReques
tDirector.java:464) ~[httpclient-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClien
t.java:820) ~[httpclient-4.1.2.jar:4.1.2]
        at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClien
t.java:754) ~[httpclient-4.1.2.jar:4.1.2]

I have come across this exception on the forums and already tried some
things to try to solve this problem. I have implemented an idle timeout
manager to monitor idle connections:
                    wait(10000);
                    if (logger.isDebugEnabled()) {
                    	logger.debug("Closing expired and idle
connections");
                    }
                    // Close expired connections
                    connMgr.closeExpiredConnections();
                    // Optionally, close connections
                    // that have been idle longer than 10 sec
                    connMgr.closeIdleConnections(10, TimeUnit.SECONDS);

I also tried to set the connection reuse strategy to 'no connection
reuse': 

httpClient.setReuseStrategy(new NoConnectionReuseStrategy());

Here is the code that I use to execute my request: since I use the
HttpEntity.writeTo method, the connection is released automatically back
to the pool.

			httpGet = new HttpGet(googleRequestUrl);
			HttpResponse googleHttpResponse =
httpClient.execute(httpGet);
			if (logger.isInfoEnabled()) {
				logger.info("Status code: {}, Reason:
{}", new String[] {
	
googleHttpResponse.getStatusLine().getStatusCode() + "",
	
googleHttpResponse.getStatusLine().getReasonPhrase() });
			}

	
response.setStatus(googleHttpResponse.getStatusLine().getStatusCode());
			HttpEntity entity =
googleHttpResponse.getEntity();
			if (entity != null) {
	
entity.writeTo(response.getOutputStream());
			}


All this with no effect: the Socket timeout exception keeps popping up
from time to time. I haven't found the exact circumstances of this
error, but it seems to me that it appears when the server is under low
load and a request is done once every few minutes. Once the load is
sufficiently high, the exception doesn't occur anymore.

Does anyone have an idea what could be the cause of the problem?

Thanks a lot and kind regards,

Frederik.




-------------------------------------------------------------------------
Dexia disclaimer:

http://www.dexia.com/maildisclaimer.htm
-------------------------------------------------------------------------