views:

1767

answers:

5

Given this stack trace snippet

Caused by: java.net.SocketException: Software caused connection abort: socket write error
 at java.net.SocketOutputStream.socketWrite0(Native Method)

I tried to answer the following questions:

  1. What code is throwing this exception? (JVM?/Tomcat?/My code?)
  2. What causes this exception to be thrown?

Regarding #1:

Sun's JVM source doesn't contain this exact message, but I think the text Software caused connection abort: socket write error is from the native implementation of SocketOutputStream:

private native void socketWrite0(FileDescriptor fd, byte[] b, int off,
                 int len) throws IOException;

Regarding #2

My guess is that it is caused when the client has terminated the connection, before getting the full response (e.g. sent a request, but before getting the full response, it got closed / terminated / offline)

Questions:

  1. Are the above assumptions correct (#1 and #2)?
  2. Can this be diffrentiated from the situation: "could not write to the client, due to a network error on the server side"? or would that render the same error message?
  3. And most important: Is there an official document (e.g from Sun) stating the above?

I need to have a proof that this stack trace is the socket client's "fault", and there is nothing that the server could have done to avoid it. (except catching the exception, or using a non Sun JVM SocketOutputStream, though both don't really avoid the fact the client has terminated)

+1  A: 

Have you checked the Tomcat source code and the JVM source ? That may give you more help.

I think your general thinking is good. I would expect a ConnectException in the scenario that you couldn't connect. The above looks very like it's client-driven.

Brian Agnew
Yes, I've checked. Tomcat's sources didn't contain any permutation of the sentence, thanks.
Ehrann Mehdan
No he hasn't checked the Tomcat source **AND** the JVM source.
Stephen C
Yes. That's very important.
Brian Agnew
Or if he has checked the JVM source, he has not checked all of it.
Stephen C
@Stephen - I've checked the JDK sources, not the JVM's native ones
Ehrann Mehdan
@Ehrann - the message string is most likely in the native sources. But you should also check the event log. IMO, the latter is likely to be more informative.
Stephen C
+1  A: 

To prove which component fails I would monitor the TCP/IP communication using wireshark and look who is actaully closing the port, also timeouts could be relevant.

stacker
+1  A: 

You don't say so, but assuming that you see this on Windows, this Sun forum posting gives a general answer to the cause of these problems.

Anything that externally interrupts your network access can cause Windows to return "software caused connection abort". It's the "General Protection Fault" of network errors ...

The posting then goes on to suggest that you look in the Windows event log for the possible cause. So, in response for your questions I would say

  • The specific cause you hypothesize may or may not be correct. You'd need to do more research, starting with looking at the Windows Event Log.
  • You have not looked at the relevant part of the JVM source yet. You need to look at the implementations of the native methods. The source code is available.
  • There is no "official" Sun document that I can find that talks about this message. Try doing a search for the message using the site search on "java.sun.com".
  • If you need an "official" Sun diagnosis, you will need to get an support contract.
  • If you want real proof, you are out of luck. Problems as complicated as this are not amenable to proof using current theorem proving technology.
Stephen C
+1  A: 

This is also caused when the connection was aborted instead of normally terminated.

Not very well documented, but the call to Socket.close() causes the connection to be aborted. This results in this Exception on the other connection side, instead of generating an EOF condition while reading.

To start a TCP's normal connection termination sequence, the client (and server) should call Socket.shutdownOutput(), see the javadoc here. This causes the other side to get an EOF if reading from the Socket, which should also be followed by a call to shutdownOutput() before closing.

Carlos Heuberger
+1  A: 

See also Some information about 'Software caused connection abort'

EJP