16

What is the difference between java.net.SocketException: Connection reset and java.net.SocketException: Broken Pipe?

I am trying to figure what are the reasons for these two exceptions. We are getting following error on our server, which is basically a soap based webservice. When I try to abort the client call the exception I am seeing is Broken pipe...

Following is the stack trace we, any help is appreciated!

2011-01-10 00:44:33,828 96893947 INFO  [STDOUT] (http-0.0.0.0-8180-Processor25:) ERROR:  ''
2011-01-10 00:44:33,829 96893948 INFO  [STDOUT] (http-0.0.0.0-8180-Processor25:) Jan 10, 2011 12:44:33 AM com.sun.xml.rpc.server.http.JAXRPCS
ervletDelegate doGetDefault
SEVERE: JAXRPCSERVLET34: transformation failed : ClientAbortException:  java.net.SocketException: Connection reset
JAXRPCSERVLET34: transformation failed : ClientAbortException:  java.net.SocketException: Connection reset
        at com.sun.xml.rpc.server.http.WSDLPublisher.handle(WSDLPublisher.java:109)
        at com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGetDefault(JAXRPCServletDelegate.java:185)
        at com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGet(JAXRPCServletDelegate.java:153)
        at com.sun.xml.rpc.server.http.JAXRPCServlet.doGet(JAXRPCServlet.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
--
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
2011-01-10 00:44:33,829 96893948 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/soa].[UserService]] (http-0.0.0.0-81
80-Processor25:) Servlet.service() for servlet UserService threw exception
javax.servlet.ServletException: JAXRPCSERVLET34: transformation failed : ClientAbortException:  java.net.SocketException: Connection reset
        at com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGetDefault(JAXRPCServletDelegate.java:347)
        at com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGet(JAXRPCServletDelegate.java:153)
        at com.sun.xml.rpc.server.http.JAXRPCServlet.doGet(JAXRPCServlet.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
Raedwald
  • 46,613
  • 43
  • 151
  • 237
Java Guy
  • 3,391
  • 14
  • 49
  • 55

4 Answers4

5

Both Connection reset and Broken pipe occurs when the connection has been closed by the peer (i.e. application holding the connection at the other side).

Connection reset can occur when writing (see java.net.SocketOutputStream) or reading (see java.net.SocketInputStream).

Broken pipe occurs in a Native method of java.net.SocketException:

java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)

Thus, Broken pipe occurs at a lower communication level, as Michael Borgwardt suggested.

In most cases, I see this error when sending a big PDF to the client browser and the user kills the browser before getting the whole document (in this case, I simply ignore the error since this was the user choice to close its browser and there is nothing to correct). But it could be other reasons (e.g. EJP suggests more reason related to data communication protocols).

Community
  • 1
  • 1
Julien Kronegg
  • 4,968
  • 1
  • 47
  • 60
  • Both occur at the same level, and you've provided no evidence to the contrary. – user207421 Jun 30 '16 at 12:02
  • 1
    @EJP: the fact that "Broken pipe" is thrown by a native method and not by Java code which shows that it is a lower **code** level. The term "communication level" should be understood as "code level", but not as a level of the OSI stack. My guess is that depending on when the client closes the connection, you get either a "broken pipe" or a "connection reset". – Julien Kronegg Jun 30 '16 at 14:33
5

'Connection reset' can occur when reading or writing. 'Broken pipe' can only occur when writing. Both are caused by writing to a connection that has already been closed by the other end, or that has been reset for some other reason.

user207421
  • 305,947
  • 44
  • 307
  • 483
4

These are error conditions on the TCP protocol level. Both of them basically mean that the other side closed the TCP connection. The difference is in what stage of communication that happens.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
0

Both are seemingly pointing to similar case - remote socket is no longer available for write.

Recently with my experiment, I found that Broken pipe occurs when my serve is on Unix env and I terminate the client.

015-06-26 10:53:51,028-0400 [ERROR][WS-ASync] (Handler.java:1168) Exception while writing ClientAbortException:  java.net.SocketException: Broken pipe
ClientAbortException:  java.net.SocketException: Broken pipe
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:413)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:371)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:438)

Whereas, when sever runs on windows, I see the connection reset exception

2015-06-26 09:11:31,491 ERROR [WS-ASync] (Handler.java:1168) - Exception while writing ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:388)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:462)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:413)
        at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
Nrj
  • 6,723
  • 7
  • 46
  • 58