Java.net.SocketException: software caused connection abort: recv failed

I could not find an adequate answer to what the following error means:

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

Notes:

  • This error is infrequent and unpredictable; although getting this error means that all future URI requests will also fail.
  • The only solution that works (also, only occasionally) is to restart Tomcat and / or the actual computer (in this case Windows).
  • The URI is definitely accessible (as confirmed by asking the browser to fetch).

Relevant Code:

 BufferedReader reader; try { URL url = new URL(URI); reader = new BufferedReader(new InputStreamReader(url.openStream()))); } catch( MalformedURLException e ) { throw new IOException("Expecting a well-formed URL: " + e); }//end try: Have a stream String buffer; StringBuilder result = new StringBuilder(); while( null != (buffer = reader.readLine()) ) { result.append(buffer); }//end while: Got the contents. reader.close(); 
+65
java sockets
Sep 25 '08 at 20:43
source share
10 answers

This usually means that a network error has occurred, such as a TCP timeout. I would start by placing a wirehark in the connection to see if you have any problems. If there is a TCP error, you should be able to see it. In addition, you can check your router logs, if applicable. If wireless is involved anywhere, this is another source of such errors.

+21
Sep 25 '08 at 20:50
source share

This also happens if your TLS client cannot be authenticated by a server configured to require client authentication.

+16
Apr 22 '14 at 12:53 on
source share

The only time I saw something like this happens when I have a bad connection or when someone closes a socket that I use from a different thread context.

+4
Sep 25 '08 at 20:49
source share

This error occurs when the connection closes abruptly (when the TCP connection is reset, while there is still data in the send buffer). The condition is very similar to the much more common "Connection reset by peer". This can happen sporadically when connected over the Internet, but also systematically if the timing is correct (for example, using keep-alive connections on the local host).

The HTTP client should simply re-open the connection and retry the request. It is important to understand that when the connection is in this state, it has no way out but to close it. Any attempt to send or receive will result in the same error.

Do not use URL.open() , use the Apache-Commons HttpClient , which has a retry mechanism, pooling, saving and many other features.

Sample Usage:

 HttpClient httpClient = HttpClients.custom() .setConnectionTimeToLive(20, TimeUnit.SECONDS) .setMaxConnTotal(400).setMaxConnPerRoute(400) .setDefaultRequestConfig(RequestConfig.custom() .setSocketTimeout(30000).setConnectTimeout(5000).build()) .setRetryHandler(new DefaultHttpRequestRetryHandler(5, true)) .build(); // the httpClient should be re-used because it is pooled and thread-safe. HttpGet request = new HttpGet(uri); HttpResponse response = httpClient.execute(request); reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); // handle response ... 
+4
Mar 28 '15 at 21:30
source share

Are you accessing HTTP data? Can you use the HttpClient library instead of the standard library? The library has more options and will provide better error messages.

http://hc.apache.org/httpclient-3.x/

+3
Sep 25 '08 at 20:49
source share

Try adding 'autoReconnect = true' to jdbc connection string

+2
Dec 28 2018-11-12T00:
source share

This will happen from time to time either in the event of a connection failure or when the remote host terminates its connection (closed application, shutting down the computer, etc.). You can avoid this by manually managing sockets and handling disconnections in your application through your communication protocol, and then call shutdownInput and shutdownOutput to clear the session.

+1
Apr 20 2018-12-12T00:
source share

See if you have another service or program running on the http port. This happened to me when I tried to use the port, and it was taken by another program.

+1
Aug 24 2018-12-12T00:
source share

If you use Netbeans to control Tomcat, try disabling the HTTP monitor in Tools-Servers.

0
Nov 11 '13 at 11:15
source share

I also had this problem. My solution was:

 sc.setSoLinger(true, 10); 

COPYING FROM WEBSITE β†’ Using the setSoLinger() method, you can explicitly set the delay before sending reset, providing more time to read or send data.

This may not be the answer for everyone, but for some people.

0
Aug 25 '14 at 5:55
source share



All Articles