Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Infamous SocketException: Broken Pipe

934824May 3 2012 — edited May 14 2012
Hello,

As with many of the other users on this forum I have been plagued by the Broken Pipe SocketException, very rarely, which seems to essentially block on the java.net.SocketOutputStream.socketWrite0(Native Method) for quite a long time (presumably the length of some timeout) during a flush. It is also typically accompanied by a "java.net.SocketException: Connection timed out" on the socket itself.

I've read the many responses by EJP that this means:

"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."

My main question is: Is it normal for these exceptions to occur, and we just need to write some layer that handles this?

And a follow up: If so, would that layer be something along the lines of:
- a separate thread on the server for each output stream, and if this thread blocks during flush (for whatever reason), either:
- use a watchdog thread to close the output if some internal timeout has exceeded, or:
- just let Java's connection timeout eventually occur and let the output thread die

Or am I way off base here?

One more thing: Any other advice / best architectural practices / help regarding this problem / reading suggestions would be extremely appreciated.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2012
Added on May 3 2012
8 comments
38,675 views