Infamous SocketException: Broken Pipe
934824May 3 2012 — edited May 14 2012Hello,
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.