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 Cyril Jaquier <cy...@jaqpot.net> on 2008/01/24 17:26:35 UTC

[HttpClient 3.1] "The operation timed out" on close

Hi all,

We are using HttpClient 3.1 on PC and PDA (Windows Mobile). On PDA, we 
get from time to time InterruptedIOException.

java.io.InterruptedIOException: The operation timed out
	at java.net.SocketImpl.receiveStreamImpl(Native Method)
	at java.net.SocketImpl.read(Unknown Source)
	at java.net.SocketInputStream.read(Unknown Source)
	at java.net.SocketInputStream.read(Unknown Source)
	at java.io.BufferedInputStream.fillbuf(Unknown Source)
	at java.io.BufferedInputStream.read(Unknown Source)
	at org.apache.commons.httpclient.ChunkedInputStream.read(Unknown Source)
	at org.apache.commons.httpclient.ChunkedInputStream.read(Unknown Source)
	at 
org.apache.commons.httpclient.ChunkedInputStream.exhaustInputStream(Unknown 
Source)
	at org.apache.commons.httpclient.ChunkedInputStream.close(Unknown Source)
	at java.io.FilterInputStream.close(Unknown Source)
	at 
org.apache.commons.httpclient.AutoCloseInputStream.notifyWatcher(Unknown 
Source)
	at org.apache.commons.httpclient.AutoCloseInputStream.close(Unknown Source)
	at java.io.FilterInputStream.close(Unknown Source)
	at java.io.FilterInputStream.close(Unknown Source)
	at java.io.FilterInputStream.close(Unknown Source)
	at java.util.zip.InflaterInputStream.close(Unknown Source)

We close all our streams before calling releaseConnection(). Do we need 
to do this? Should we call releaseConnection() BEFORE closing the streams?

About the above exception, I guess that the underlaying GPRS connection 
(or the server!?) went away right before closing the stream. And as 
ChunkedInputStream.close() does not close the stream but tries to read 
more data, this InterruptedIOException is thrown.

Could we just ignore this exception or do we need to cleanup something 
else in this case?

Thank you.

Regards,

Cyril Jaquier

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


Re: [HttpClient 3.1] "The operation timed out" on close

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2008-01-25 at 14:41 +0100, Cyril Jaquier wrote:
> Hi Oleg,
> 
> Thank you for your reply.
> 
> > You do not have to close the input stream returned by
> > #getResponseBodyAsStream, as it is not guaranteed to close the
> > underlying socket (in fact #releaseConnection() will be called behind
> > the scene) but generally it is a good practice to do so.
> > 
> 
> Ok. But where and when will be the underlaying socket closed? I can't 
> find this in the code :( Wait wait wait... This socket shouldn't be 
> closed at all in order to satisfy (if needed) the "Keep-Alive" mode. So 
> the socket is managed (in our case) by the 
> MultiThreadedHttpConnectionManager I guess. Am I right?
> 

Yes, you are.

Oleg

> > I _suspect_ the server simply fails to send the closing chunk. If the
> > message body appears to be in a consistent state you can just ignore the
> > exception. You might want to investigate a little further, though.
> > Enable the wire log and see if the closing chunk is indeed missing.
> > 
> 
> As we only observe this on mobile devices, I think this should be 
> related to the GPRS connection, Windows Mobile or J9. But as this only 
> happens sporadically, I guess we can just throw the exception to our 
> client upper layers which will then display an error or retry.
> 
> Regards,
> 
> Cyril Jaquier
> 
> ---------------------------------------------------------------------
> 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: [HttpClient 3.1] "The operation timed out" on close

Posted by Cyril Jaquier <cy...@jaqpot.net>.
Hi Oleg,

Thank you for your reply.

> You do not have to close the input stream returned by
> #getResponseBodyAsStream, as it is not guaranteed to close the
> underlying socket (in fact #releaseConnection() will be called behind
> the scene) but generally it is a good practice to do so.
> 

Ok. But where and when will be the underlaying socket closed? I can't 
find this in the code :( Wait wait wait... This socket shouldn't be 
closed at all in order to satisfy (if needed) the "Keep-Alive" mode. So 
the socket is managed (in our case) by the 
MultiThreadedHttpConnectionManager I guess. Am I right?

> I _suspect_ the server simply fails to send the closing chunk. If the
> message body appears to be in a consistent state you can just ignore the
> exception. You might want to investigate a little further, though.
> Enable the wire log and see if the closing chunk is indeed missing.
> 

As we only observe this on mobile devices, I think this should be 
related to the GPRS connection, Windows Mobile or J9. But as this only 
happens sporadically, I guess we can just throw the exception to our 
client upper layers which will then display an error or retry.

Regards,

Cyril Jaquier

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


Re: [HttpClient 3.1] "The operation timed out" on close

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2008-01-24 at 17:26 +0100, Cyril Jaquier wrote:
> Hi all,
> 
> We are using HttpClient 3.1 on PC and PDA (Windows Mobile). On PDA, we 
> get from time to time InterruptedIOException.
> 
> java.io.InterruptedIOException: The operation timed out
> 	at java.net.SocketImpl.receiveStreamImpl(Native Method)
> 	at java.net.SocketImpl.read(Unknown Source)
> 	at java.net.SocketInputStream.read(Unknown Source)
> 	at java.net.SocketInputStream.read(Unknown Source)
> 	at java.io.BufferedInputStream.fillbuf(Unknown Source)
> 	at java.io.BufferedInputStream.read(Unknown Source)
> 	at org.apache.commons.httpclient.ChunkedInputStream.read(Unknown Source)
> 	at org.apache.commons.httpclient.ChunkedInputStream.read(Unknown Source)
> 	at 
> org.apache.commons.httpclient.ChunkedInputStream.exhaustInputStream(Unknown 
> Source)
> 	at org.apache.commons.httpclient.ChunkedInputStream.close(Unknown Source)
> 	at java.io.FilterInputStream.close(Unknown Source)
> 	at 
> org.apache.commons.httpclient.AutoCloseInputStream.notifyWatcher(Unknown 
> Source)
> 	at org.apache.commons.httpclient.AutoCloseInputStream.close(Unknown Source)
> 	at java.io.FilterInputStream.close(Unknown Source)
> 	at java.io.FilterInputStream.close(Unknown Source)
> 	at java.io.FilterInputStream.close(Unknown Source)
> 	at java.util.zip.InflaterInputStream.close(Unknown Source)
> 
> We close all our streams before calling releaseConnection(). Do we need 
> to do this? 

Cyril,

You do not have to close the input stream returned by
#getResponseBodyAsStream, as it is not guaranteed to close the
underlying socket (in fact #releaseConnection() will be called behind
the scene) but generally it is a good practice to do so.


> Should we call releaseConnection() BEFORE closing the streams?
> 

No.

> About the above exception, I guess that the underlaying GPRS connection 
> (or the server!?) went away right before closing the stream. And as 
> ChunkedInputStream.close() does not close the stream but tries to read 
> more data, this InterruptedIOException is thrown.
> 
> Could we just ignore this exception or do we need to cleanup something 
> else in this case?
> 

I _suspect_ the server simply fails to send the closing chunk. If the
message body appears to be in a consistent state you can just ignore the
exception. You might want to investigate a little further, though.
Enable the wire log and see if the closing chunk is indeed missing.

Hope this helps

Oleg   


> Thank you.
> 
> Regards,
> 
> Cyril Jaquier
> 
> ---------------------------------------------------------------------
> 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