HttpClient 4.0. SocketTimeoutException and RST signal problem

View: New views
4 Messages — Rating Filter:   Alert me  

HttpClient 4.0. SocketTimeoutException and RST signal problem

by tompra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have problem with RST signal from instance of HttpClient that invokes a SocketTimeoutException: Read Timeout.

In an attachement there is an image of network communication between my client and server, where client invokes RST.

SocketTimeoutException1.jpg

My client makes a lot of correct requests but sometimes there is a problem with RST. Sometimes comes many SocketTimeoutException in the same time and than we haven't problem several next hours. Can the server be a reason of this problem?

The exception is:

class java.net.SocketTimeoutException:
 Read timed out
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:130)
org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:127)
org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:233)
org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:210)
org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:271)
org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:227)
org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:229)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:292)
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:126)
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)

My code is:

HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 30000);
HttpConnectionParams.setSoTimeout(params, 30000);
           
HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler(3, true);

DefaultHttpClient httpClient = new DefaultHttpClient(params);
httpClient.setHttpRequestRetryHandler(retryHandler);
 
HttpGet httpGet = new HttpGet(URIUtil.encodeQuery(targetUrl));
       
HttpResponse response = httpClient.execute(httpGet);

HttpEntity entity = response.getEntity();
if (entity == null) {
            throw new ....
}

String content = EntityUtils.toString(entity);

Can you help me and show me the way? Thank you.

Best regards,

Tom

Re: HttpClient 4.0. SocketTimeoutException and RST signal problem

by tompra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Anyone?

Do you have any idea? Where I made a mistake?

Tom

tompra wrote:
Hi,

I have problem with RST signal from instance of HttpClient that invokes a SocketTimeoutException: Read Timeout.

Re: HttpClient 4.0. SocketTimeoutException and RST signal problem

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

tompra wrote:
> Hi,
>
> I have problem with RST signal from instance of HttpClient that invokes a
> SocketTimeoutException: Read Timeout.
>

This is because HttpClient automatically closes connections that time
out on an I/O operation.

> In an attachement there is an image of network communication between my
> client and server, where client invokes RST.
>
> http://www.nabble.com/file/p25911599/SocketTimeoutException1.jpg
> SocketTimeoutException1.jpg
>
> My client makes a lot of correct requests but sometimes there is a problem
> with RST. Sometimes comes many SocketTimeoutException in the same time and
> than we haven't problem several next hours. Can the server be a reason of
> this problem?

Yes, absolutely. Most likely this is a server related issue.

>
> The exception is:
>
> class java.net.SocketTimeoutException:
>  Read timed out
> java.net.SocketInputStream.socketRead0(Native Method)
> java.net.SocketInputStream.read(SocketInputStream.java:129)
> org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:130)
> org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:127)
> org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:233)
> org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
> org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:210)
> org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:271)
> org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:227)
> org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:229)
> org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:292)
> org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:126)
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
>
> My code is:
>
> HttpParams params = new BasicHttpParams();
> HttpConnectionParams.setConnectionTimeout(params, 30000);
> HttpConnectionParams.setSoTimeout(params, 30000);
>    
> HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler(3,
> true);
>
> DefaultHttpClient httpClient = new DefaultHttpClient(params);
> httpClient.setHttpRequestRetryHandler(retryHandler);
>  
> HttpGet httpGet = new HttpGet(URIUtil.encodeQuery(targetUrl));
>        
> HttpResponse response = httpClient.execute(httpGet);
>
> HttpEntity entity = response.getEntity();
> if (entity == null) {
>             throw new ....
> }
>
> String content = EntityUtils.toString(entity);
>
> Can you help me and show me the way? Thank you.
>

Maybe 30 second timeout is just too small. Try setting it to a greater
number (3 minutes, for instance).

Oleg


> Best regards,
>
> Tom




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...


Re: HttpClient 4.0. SocketTimeoutException and RST signal problem

by tompra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you for your help. I increse timeouts and connector is running fine without problems.

Best Regards,

Tom