views:

1043

answers:

2

Hi,

I am using apache commons http client to call url using post method to post the parameters and getting the below error rarely. When I explore the reason, didnt get the exact reason for the cause. Can anyone suggest a way to fix this?

java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
        at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
        at org.apache.commons.httpclient.methods.ByteArrayRequestEntity.writeRequest(ByteArrayRequestEntity.java:90)
        at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
        at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
        at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
A: 

I'm not sure that this is the case, but I got something similar when I transferred objects (through object streams) too often. As I remember, 15-20 calls per seconds were enough to overload pipes and exception was thrown (something like 'ObjectStream corrupted').

The only solution I found was to reduce number of calls due to enlarging amount of data transferred per one call.

Roman
'ObjectStream corrupted' would only occur if your application corrupted it. It isn't a function of load. Neither is this thread.
EJP
Believe me, I spent about a month and almost was banned at google before found suitable solution.
Roman
Read this article for more info http://www.javamex.com/tutorials/io/StreamCorruptedException.shtml. In nutshell: we have some maximum capacity, let's assume 10 calls per second. When we want to make 20 calls we get huge problem.
Roman
@Roman - how does the the linked article describe your problem? I don't see the connection.
Stephen C
@Stephen C: I actually don't have any problem, it was solved more than a year ago. Text in the beginning of the article describes my former problem a little. Let's stop this discussion, please.
Roman
+1  A: 

This is caused by writing to a connection when the other end has already closed it.

So you have a poorly defined or implemented application protocol.

EJP
Can you please help me to identify and correct it? Basically, how to confirm the reason and fix?
Mani
I *have* confirmed the reason. You are writing while the other end has already closed the connection. The fix is not to do that. As the other end isn't reading it, there isn't any point anyway. As I also said, if this is happening there is something wrong with your application protocol specification or implementation, most probably that you don't even have one.
EJP
Thanks. Server side app has been implemented using HTTP protocol. It is running under tomcat. Am I doing any mistake in specifying headers? Also, Is it possible to identify whether the other end has already closed the connection in the client side code?
Mani
If the server side HTTP application is getting Broken Pipe exceptions it just means the client browser has exited/gone to another page/timed out/gone back in the history/whatever. Just forget about it.
EJP
In my case, it is happening in client side only.
Mani
So the *server* is closing the connection early. You're probably sending it something invalid.
EJP