« Return to Thread: Http Client 4.0 dead locks with spotty internet coverage

Re: Http Client 4.0 dead locks with spotty internet coverage

by olegk :: Rate this Message:

Reply to Author | View in Thread

David Spectar wrote:

> Greetings fello Http Client Users,
>
> I was trying out HttpClient 4.0 and noticed that I could easily get the code to deadlock when my internet coverage would go down. It didn't happen every time it went down, but if I had WIFI on that went down every couple of minutes and say I was trying to continuously make HTTP GET requests, eventually the code would deadlock.
>
> I'd love to hear your thoughts on this. See below for stack trace and code.
>
> Thanks for looking.
> David
>
> Here is the stack trace.
> java.et.SocketInputStream.socketRead0(Native Method) // Code stays stuck here forever.

Hi David

This problem has nothing to do with HttpClient. As you can see the
thread is blocked in a native method call. Use a socket timeout to make
sure I/O operations do not get stuck indefinitely.

Oleg


> java.net.SocketInputStream.read(Unknown Source)
> 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:82)
> 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:235)
> org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
> 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:410)
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
> MyCode.foo(MyCode.java:33)
>
> Here is a simplified version of my code (taken from the Multi Threading example code, but it did the same in the non-threading version)
> HttpParams params = new BasicHttpParams();
> ConnManagerParams.setMaxTotalConnections(params, 100);
> HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
> SchemeRegistry schemeRegistry = new SchemeRegistry();
> schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
>
> ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
> DefaultHttpClient defHttpClient = new DefaultHttpClient(cm, params);
> defHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(MaxRetries, true));
>
> HttpGet httpGet = new HttpGet("http://www.google.com");
> HttpContext context = new BasicHttpContext();
> HttpResponse response = HttpClient.execute(httpGet, context); // This method never returns
> // more code below that is never executed.
>
>
>
>       Get your preferred Email name!
> Now you can @ymail.com and @rocketmail.com.
> http://mail.promotions.yahoo.com/newdomains/aa/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>


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

 « Return to Thread: Http Client 4.0 dead locks with spotty internet coverage