Official reasons for "Software caused connection abort: socket write error"
Asked Answered
C

14

171

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)

Chassis answered 24/1, 2010 at 9:52 Comment(4)
I have this issue when cancelling a download with FirefoxKnowling
Hey Eran I am also getting this exception while sending/writing (outs.write(audioBytes);) byte[] in to OutputStream. When audio is plying and while playing if user clicks on any other menu (which send an server request) I got the same error on console. so is it safe to ignore this exception?Emboly
@Emboly - It seems so, yes. Basically from what the answers describe, this is a Windows specific error, but I assume on Linux you'll get the same exception just with a different wording... (My laymen terms understanding of it is basically that this is caused when you send via a socket to some remote location X and X got disconnected in the middle, but I'm sure it's not the most accurate way to describe it)Chassis
For me this happened when the database server was restarted and the application was still trying to query using connections previously opened. Not sure why these were not refreshed as we're using DBCP based pooling. But restarting the application fixed the problem.Matelot
C
56

This error can occur when the local network system aborts a connection, such as when WinSock closes an established connection after data retransmission fails (receiver never acknowledges data sent on a datastream socket).

See this MSDN article. See also Some information about 'Software caused connection abort'.

Crosslegged answered 12/10, 2011 at 23:17 Comment(8)
WSAECONNABORTED - An understandable explanationBrownnose
@MatGessel That article just repeats the confusion, and adds some of its own. WSAECONNABORTED is a Winsock error code, so there cannot possibly be a Berkeley explanation for it. The situation described about the HTTP server would produce ECONNRESET, not WSAECONNABORTED.Crosslegged
@EJP, I am also getting this exception while sending/writing (outs.write(audioBytes);) byte[] in to OutputStream. When audio is plying and while playing if user clicks on any other menu (which send an server request) I got the same error on console. so is it safe to ignore this exception?Emboly
ECONNRESET is produced when there is no data in the send buffer, when there is, WSAECONNABORTED is produced. Maybe the article adds to your confusion EJP but is otherwise perfectly accurate.Wilde
@Wilde All three sources cited here state that it is produced by ACK failures. If you have a source for your own claim please cite it.Crosslegged
This is not a real answer as it doesn't give you information to pursue the problem further. The answer here is basically "something bad happened on the network". It would be really helpful to understand what further logs and other records of activity could allow me to pinpoint the underlying issue.Quart
@DerekBennet The underlying issue is stated in this answer. Your comment is baffling.Crosslegged
Most of the readers of this post will experience this error outside of their program's code. I encountered this error when Oracle suddenly dropped a bunch of active connections in which my app was participating. This happened on multiple machines simultaneously. What about that scenario could cause TCP re-transmission to fail? The example in this link is more explanatory: chilkatsoft.com/p/p_299.asp I am guessing that I need to look at router and switch logs. But, I am still unsure.Quart
B
17

The java.net.SocketException is thrown when there is an error creating or accessing a socket (such as TCP). This usually can be caused when the server has terminated the connection (without properly closing it), so before getting the full response. In most cases this can be caused either by the timeout issue (e.g. the response takes too much time or server is overloaded with the requests), or the client sent the SYN, but it didn't receive ACK (acknowledgment of the connection termination). For timeout issues, you can consider increasing the timeout value.

The Socket Exception usually comes with the specified detail message about the issue.

Example of detailed messages:

  • Software caused connection abort: recv failed.

    The error indicates an attempt to send the message and the connection has been aborted by your server. If this happened while connecting to the database, this can be related to using not compatible Connector/J JDBC driver.

    Possible solution: Make sure you've proper libraries/drivers in your CLASSPATH.

  • Software caused connection abort: connect.

    This can happen when there is a problem to connect to the remote. For example due to virus-checker rejecting the remote mail requests.

    Possible solution: Check Virus scan service whether it's blocking the port for the outgoing requests for connections.

  • Software caused connection abort: socket write error.

    Possible solution: Make sure you're writing the correct length of bytes to the stream. So double check what you're sending. See this thread.

  • Connection reset by peer: socket write error / Connection aborted by peer: socket write error

    The application did not check whether keep-alive connection had been timed out on the server side.

    Possible solution: Ensure that the HttpClient is non-null before reading from the connection.E13222_01

  • Connection reset by peer.

    The connection has been terminated by the peer (server).

  • Connection reset.

    The connection has been either terminated by the client or closed by the server end of the connection due to request with the request.

    See: What's causing my java.net.SocketException: Connection reset?

Bowen answered 25/8, 2016 at 11:11 Comment(1)
Only one of these 6 points actually answers the question, incorrectly. Several others are incorrect as well. The application can't 'check whether keep-alive connection had been timed out on the server side.' The HttpClient being null cannot possibly cause a SocketException. Not writing the correct length to the stream doesn't either.Crosslegged
A
11

I have seen this most often when a corporate firewall on a workstation/laptop gets in the way, it kills the connection.

eg. I have a server process and a client process on the same machine. The server is listening on all interfaces (0.0.0.0) and the client attempts a connection to the public/home interface (note not the loopback interface 127.0.0.1).

If the machine is has its network disconnected (eg wifi turned off) then the connection is formed. If the machine is connected to the corporate network (directly or vpn) then the connection is formed.

However, if the machine is connected to a public wifi (or home network) then the firewall kicks in an kills the connection. In this situation connecting the client to the loopback interface works fine, just not to the home/public interface.

Hope this helps.

Adara answered 31/1, 2013 at 11:46 Comment(1)
Firewalls prevent connections. The question is about resetting an existing connection.Crosslegged
E
4

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.

Euchromosome answered 24/1, 2010 at 11:1 Comment(3)
Nobody is closing the port. The operating system is aborting the connection.Crosslegged
@EJP I've seen this happen when the gets overloaded and runs out of memory. I am not sure it is the OS that closes the connection but JVM goes wild.Karr
@Karr There is a difference between closing a port, which is visible as a FIN in Wireshark, and aborting the connection, which isn't.Crosslegged
L
3

For anyone using simple Client Server programms and getting this error, it is a problem of unclosed (or closed to early) Input or Output Streams.

Letishaletitia answered 25/11, 2014 at 7:33 Comment(1)
No it isn't. That would consitute a socket leak, which would eventually cause an FD exhaustion.Crosslegged
U
2

Had an SSLPoke.bat (SSL troubleshooting script) window script that was getting this error despite importing the correct certificates into the cacerts trustore.

C:\Java\jdk1.8.0_111\jre\lib\security>SSLPoke.bat

C:\Java\jdk1.8.0_111\jre\lib\security>"C:\jdk1.8.0_101\jre\bin\java" 
     `SSLPoke  tfs.corp.****.com  443`

java.net.SocketException: Software caused connection abort: recv failed
    `at java.net.SocketInputStream.socketRead0(Native Method)`
    `at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)`
    `at java.net.SocketInputStream.read(SocketInputStream.java:170)`
    `at java.net.SocketInputStream.read(SocketInputStream.java:141)`
    `at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)`
    `at sun.security.ssl.InputRecord.read(InputRecord.java:503)`
    `at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)`
    `at sun.security.ssl.SSLSocketImpl.performInitialHandshake
       (SSLSocketImpl.java:1375)`
    `at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)`
    `at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)`
    `at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:138)`
    `at SSLPoke.main(SSLPoke.java:28)`

I then checked some old notes about some network changes at my job. We would need in some cases to add the JVM parameter -Djava.net.preferIPv4Stack=true to make connections to certain machines in our network to avoid this error.

C:\Java\jdk1.8.0_111\jre\lib\security>"C:\Java\jdk1.8.0_111\bin\java"  
    **-Djava.net.preferIPv4Stack=true**  SSLPoke tfs.corp.****.com 443

Successfully connected

The code for SSLPoke can be downloaded from here: https://gist.github.com/4ndrej/4547029

Uzial answered 27/10, 2021 at 19:53 Comment(1)
I was facing similar issue, your answer helped me. Thank youEllsworth
R
1

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.

Riata answered 24/1, 2010 at 9:57 Comment(7)
Yes, I've checked. Tomcat's sources didn't contain any permutation of the sentence, thanks.Chassis
No he hasn't checked the Tomcat source AND the JVM source.Wrongdoing
Or if he has checked the JVM source, he has not checked all of it.Wrongdoing
@Stephen - I've checked the JDK sources, not the JVM's native onesChassis
@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.Wrongdoing
This message string comes from the operating system actually.Crosslegged
@EJP yep, I should have searched there first, a naive assumption that Java would normalize/translate OS specific errors probably. Thanks for the clarificationChassis
S
1

I was facing the same issue.
Commonly This kind of error occurs due to client has closed its connection and server still trying to write on that client.
So make sure that your client has its connection open until server done with its outputstream.
And one more thing, Don`t forgot to close input and output stream.

Hope this helps.
And if still facing issue than brief your problem here in details.

Scrupulous answered 28/6, 2016 at 11:41 Comment(1)
@BhavinChhatrola No, an incorrect answer. The situation described produces 'connection reset by peer', not the error in the question.Crosslegged
H
0

This error happened to me while testing my soap service with SoapUI client, basically I was trying to get a very big message (>500kb) and SoapUI closed the connection by timeout.

On SoapUI go to:

File-->Preferences--Socket Timeout(ms)

...and put a large value, such as 180000 (3 minutes), this won't be the perfect fix for your issue because the file is in fact to large, but at least you will have a response.

Hula answered 22/9, 2016 at 9:19 Comment(0)
E
0

Closed connection in another client

In my case, the error was:

java.net.SocketException: Software caused connection abort: recv failed

It was received in eclipse while debugging a java application accessing a H2 database. The source of the error was that I had initially opened the database with SQuirreL to check manually for integrity. I did use the flag to enable multiple connections to the same DB (i.e. AUTO_SERVER=TRUE), so there was no problem connecting to the DB from java.

The error appeared when, after a while --it is a long java process-- I decided to close SQuirreL to free resources. It appears as if SQuirreL were the one "owning" the DB server instance and that it was shut down with the SQuirreL connection.

Restarting the Java application did not yield the error again.

config

  • Windows 7
  • Eclipse Kepler
  • SQuirreL 3.6
  • org.h2.Driver ver 1.4.192
Extend answered 23/2, 2017 at 12:22 Comment(0)
U
0

In the situation explained below, client side will throw such an exception:

The server is asked to authenticate client certificate, but the client provides a certificate which Extended Key Usage doesn't support client auth, so the server doesn't accept the client's certificate, and then it closes the connection.

Urfa answered 13/10, 2017 at 1:5 Comment(2)
This answer is incorrect. In the case you describe an SSLException will be thrown.Antiphrasis
actually it throw SocketException just like the current question , i had testedUrfa
T
-1

My server was throwing this exception in the pass 2 days and I solved it by moving the disconnecting function with:

outputStream.close();
inputStream.close();
Client.close();

To the end of the listing thread. if it will helped anyone.

Tippler answered 27/9, 2015 at 12:56 Comment(0)
A
-1

In my case, I developped the client and the server side, and I have the exception :

Cause : error marshalling arguments; nested exception is: java.net.SocketException: Software caused connection abort: socket write error

when classes in client and server are different. I don't download server's classes (Interfaces) on the client, I juste add same files in the project. But the path must be exactly the same. For example, on the server project I have java\rmi\services packages with some serviceInterface and implementations, I have to create the same package on the client project. If I change it by java/rmi/server/services for example, I get the above exception. Same exception if the interface version is different between client and server (even with an empty row added inadvertently ... I think rmi makes a sort of hash of classes to check version ... I don't know... If it could help ...

Annabel answered 20/12, 2019 at 8:16 Comment(0)
S
-3

I was facing the same problem with wireMock while mocking the rest API calls. Earlier I was defining the server like this:

WireMockServer wireMockServer = null;

But it should be defined like as shown below:

@Rule 
public WireMockRule wireMockRule = new WireMockRule(8089);
Sigh answered 1/12, 2016 at 10:35 Comment(1)
That would cause a NullPointerException, not this problem.Crosslegged

© 2022 - 2024 — McMap. All rights reserved.