You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "David Tonhofer, m-plify S.A." <d....@m-plify.com> on 2004/07/09 19:37:34 UTC

Bytes written over the 'wire' are dropped on the floor?

Hello,

I have spent the past few hours tracking down a problem that seems to
occur if you push bytes too quickly over a socket. As it happened with
HTTPClient, I though I might ask here. Maybe somebody has already heard
about it and can tell me whether there is a simple trick I don't know about.

First, this happens under W2K, with Sun JVM 1.4.1. Haven't tried it on
Linux yet (if anyone is interested, let me know).

The HTTPClient I use is the 2.0 version.

The HTTP Server is a simple homegrown Java socket-handling framework
it basically just reads the bytes from the InputStream that it obtains
from the socket.

Problem:
--------

If I issue HTTPClient POST requests really quickly (in this case, inside
a tight loop), then the first two request are received ok. On the third request,
the data written over the 'wire' (note that the network is not really involved,
client and server are on the same machine) seems to be dropped on the floor, i.e.
the server receives the HTTP header, the HTTP header endline, and I can see
HTTPClient log that it wrote the request body, but the request body is never
received on the server side, even if the server waits a whole minute. I have
tried to use InputStream and BufferedInputStream, but to avail.

Le fixe:
--------

What fixed the problem was the introduction of a little delay in
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpState state, HttpConnection conn),
just before the 'flush' of the body. This (line 2322 in HttpMethodBase):

 ...
 writeRequestBody(state, conn);
 // make sure the entire request body has been sent
 conn.flushRequestOutputStream();
 ....

is 'augmented' with this:

 ...
 writeRequestBody(state, conn);
 try {
   Thread.sleep(20);
 }
 catch (Exception exe) {
 }
 conn.flushRequestOutputStream();
 ...

I think I have already encountered this problem with Java 1.2 a few years ago,
also on W2K (indeed I have found a 500ms sleep in some old code I have been keeping
around). Does anyone know if this is a common phenomenon?

Best regards and thanks in advance for any clue,

	-- David Tonhofer



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: Bytes written over the 'wire' are dropped on the floor?

Posted by Oleg Kalnichevski <ol...@apache.org>.
David,

What is the <strong>exact</strong> version of JRE you are using? Early
releases of Sun's Java 1.4.0.x and 1.4.1.x were SO buggy that it is not
even worth the trouble looking onto the problem unless you can confirm
the problem is reproducible with Java 1.4.2.2 or above

Oleg

On Fri, 2004-07-09 at 19:37, David Tonhofer, m-plify S.A. wrote:
> Hello,
> 
> I have spent the past few hours tracking down a problem that seems to
> occur if you push bytes too quickly over a socket. As it happened with
> HTTPClient, I though I might ask here. Maybe somebody has already heard
> about it and can tell me whether there is a simple trick I don't know about.
> 
> First, this happens under W2K, with Sun JVM 1.4.1. Haven't tried it on
> Linux yet (if anyone is interested, let me know).
> 
> The HTTPClient I use is the 2.0 version.
> 
> The HTTP Server is a simple homegrown Java socket-handling framework
> it basically just reads the bytes from the InputStream that it obtains
> from the socket.
> 
> Problem:
> --------
> 
> If I issue HTTPClient POST requests really quickly (in this case, inside
> a tight loop), then the first two request are received ok. On the third request,
> the data written over the 'wire' (note that the network is not really involved,
> client and server are on the same machine) seems to be dropped on the floor, i.e.
> the server receives the HTTP header, the HTTP header endline, and I can see
> HTTPClient log that it wrote the request body, but the request body is never
> received on the server side, even if the server waits a whole minute. I have
> tried to use InputStream and BufferedInputStream, but to avail.
> 
> Le fixe:
> --------
> 
> What fixed the problem was the introduction of a little delay in
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpState state, HttpConnection conn),
> just before the 'flush' of the body. This (line 2322 in HttpMethodBase):
> 
>  ...
>  writeRequestBody(state, conn);
>  // make sure the entire request body has been sent
>  conn.flushRequestOutputStream();
>  ....
> 
> is 'augmented' with this:
> 
>  ...
>  writeRequestBody(state, conn);
>  try {
>    Thread.sleep(20);
>  }
>  catch (Exception exe) {
>  }
>  conn.flushRequestOutputStream();
>  ...
> 
> I think I have already encountered this problem with Java 1.2 a few years ago,
> also on W2K (indeed I have found a 500ms sleep in some old code I have been keeping
> around). Does anyone know if this is a common phenomenon?
> 
> Best regards and thanks in advance for any clue,
> 
> 	-- David Tonhofer
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: Bytes written over the 'wire' are dropped on the floor?

Posted by Eric Johnson <er...@tibco.com>.
Make sure you are using the MultiThreadedConnectionManager, and that you 
call releaseConnection after each request.  It strikes me that you could 
be getting into a situation where the server thinks it is doing HTTP 
pipelining, which HttpClient doesn't actually support, particularly if 
you are not "releasing" the connection properly.

Presumably, if you can stop the code in the debugger, you can tell 
exactly which line in HttpClient is blocked.  You don't seem to mention 
that below.  That could be a valuable hint.

As with many httpclient support issues, if you provide a trace log in a 
subsequent email, that might quickly reveal the problem.  You might also 
try on a 1.4.2 vintage JVM, to see if you get different behavior.

-Eric.

David Tonhofer, m-plify S.A. wrote:

> Hello,
>
> I have spent the past few hours tracking down a problem that seems to
> occur if you push bytes too quickly over a socket. As it happened with
> HTTPClient, I though I might ask here. Maybe somebody has already heard
> about it and can tell me whether there is a simple trick I don't know 
> about.
>
> First, this happens under W2K, with Sun JVM 1.4.1. Haven't tried it on
> Linux yet (if anyone is interested, let me know).
>
> The HTTPClient I use is the 2.0 version.
>
> The HTTP Server is a simple homegrown Java socket-handling framework
> it basically just reads the bytes from the InputStream that it obtains
> from the socket.
>
> Problem:
> --------
>
> If I issue HTTPClient POST requests really quickly (in this case, inside
> a tight loop), then the first two request are received ok. On the 
> third request,
> the data written over the 'wire' (note that the network is not really 
> involved,
> client and server are on the same machine) seems to be dropped on the 
> floor, i.e.
> the server receives the HTTP header, the HTTP header endline, and I 
> can see
> HTTPClient log that it wrote the request body, but the request body is 
> never
> received on the server side, even if the server waits a whole minute. 
> I have
> tried to use InputStream and BufferedInputStream, but to avail.
>
> Le fixe:
> --------
>
> What fixed the problem was the introduction of a little delay in
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpState 
> state, HttpConnection conn),
> just before the 'flush' of the body. This (line 2322 in HttpMethodBase):
>
> ...
> writeRequestBody(state, conn);
> // make sure the entire request body has been sent
> conn.flushRequestOutputStream();
> ....
>
> is 'augmented' with this:
>
> ...
> writeRequestBody(state, conn);
> try {
>   Thread.sleep(20);
> }
> catch (Exception exe) {
> }
> conn.flushRequestOutputStream();
> ...
>
> I think I have already encountered this problem with Java 1.2 a few 
> years ago,
> also on W2K (indeed I have found a 500ms sleep in some old code I have 
> been keeping
> around). Does anyone know if this is a common phenomenon?
>
> Best regards and thanks in advance for any clue,
>
>     -- David Tonhofer
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org