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 David Spectar <ds...@yahoo.com> on 2009/06/17 07:47:33 UTC

Http Client 4.0 dead locks with spotty internet coverage

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.net.SocketInputStream.socketRead0(Native Method) // Code stays stuck here forever.
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@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Http Client 4.0 dead locks with spotty internet coverage

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, Jun 19, 2009 at 10:50:19PM -0700, David Spectar wrote:
> 
> Oleg,
> 
> Thank you for responding to everybody. We appreciate your willingness to help out. 
> 
> The only way I can see to "use a socket timeout" as you suggested was to use a different Socket Factory than the one uses in the code
>       schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
> 
> Am I heading down the right path? Or should I somehow grab the socket from HttpClient and set it's timeout?
> 
> Thanks,
> Michael
> 

Michael,

Simply use 'http.socket.timeout' parameter

http://wiki.apache.org/HttpComponents/HttpClientTutorial

Oleg

> 
> 
> ----- Original Message ----
> From: Oleg Kalnichevski <ol...@apache.org>
> To: HttpClient User Discussion <ht...@hc.apache.org>
> Sent: Wednesday, June 17, 2009 12:09:37
> Subject: Re: Http Client 4.0 dead locks with spotty internet coverage
> 
> 
> 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
> 
> 
>       New Email addresses available on Yahoo!
> Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
> Hurry before someone else does!
> http://mail.promotions.yahoo.com/newdomains/aa/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

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


Re: Http Client 4.0 dead locks with spotty internet coverage

Posted by David Spectar <ds...@yahoo.com>.
Oleg,

Thank you for responding to everybody. We appreciate your willingness to help out. 

The only way I can see to "use a socket timeout" as you suggested was to use a different Socket Factory than the one uses in the code
      schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

Am I heading down the right path? Or should I somehow grab the socket from HttpClient and set it's timeout?

Thanks,
Michael



----- Original Message ----
From: Oleg Kalnichevski <ol...@apache.org>
To: HttpClient User Discussion <ht...@hc.apache.org>
Sent: Wednesday, June 17, 2009 12:09:37
Subject: Re: Http Client 4.0 dead locks with spotty internet coverage


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


      New Email addresses available on Yahoo!
Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/

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


Re: Http Client 4.0 dead locks with spotty internet coverage

Posted by Oleg Kalnichevski <ol...@apache.org>.
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@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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