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 Kireet Reddy <ki...@feedly.com> on 2012/08/18 08:03:55 UTC
infinite loop in ContentInputStream.close()
I recently started using HttpAsyncClient but occasionally my code would
hang. After debugging, I found that ContentInputStream.close() would get
stuck in an infinite loop at line 86 when there is no content in the
SimpleInputBuffer. Is this a known issue? For now I just did a workaround
by using a response consumer that produces a single whitespace character
response when there is no content.
Thanks.
Re: infinite loop in ContentInputStream.close()
Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
Hi Kireet,
To avoid such issues (I faces many time issues where it's not
responsing or timeout is not respected), I have implemented something
like that and I'm doing all the calls that way. I might be possible to
improve it. I did it very quickly.
JM
public HttpResponse executeSafe (final DefaultHttpClient client,
final HttpUriRequest method) throws Exception
{
final HttpResponsResult result = new HttpResponsResult ();
Thread thread = new Thread("executeSafe")
{
public void run ()
{
try
{
result.result = client.execute (method);
}
catch (NullPointerException e)
{
result.npe = e;
}
catch (ClientProtocolException e)
{
result.cpe = e;
}
catch (IOException e)
{
result.ioe = e;
}
catch (Exception e)
{
System.out.println("Initial set of cookies:");
List<Cookie> cookies = client.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
result.e = e;
}
}
};
thread.start();
long timeout = System.currentTimeMillis() + 45 * 1000; // Exit after
45 seconds and ignore the respons.
while (thread.isAlive() && (System.currentTimeMillis() < timeout))
{
try{Thread.sleep (10);} catch (InterruptedException e){e.printStackTrace();}
}
if (thread.isAlive())
{
System.out.println (currentThread().getName() + " Timeout! Killing
it! " + method.getURI());
method.abort();
thread.interrupt();
}
if (result.cpe != null)
throw result.cpe;
if (result.ioe != null)
throw result.ioe;
if (result.e != null)
throw result.e;
if (result.npe != null)
exit = true;
return result.result;
}
2012/8/18, Kireet Reddy <ki...@feedly.com>:
> I recently started using HttpAsyncClient but occasionally my code would
> hang. After debugging, I found that ContentInputStream.close() would get
> stuck in an infinite loop at line 86 when there is no content in the
> SimpleInputBuffer. Is this a known issue? For now I just did a workaround
> by using a response consumer that produces a single whitespace character
> response when there is no content.
>
> Thanks.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org