views:

6140

answers:

3

I haven't been able to find an adequate answer to what exactly 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 requests for URIs will also fail.
  • The only solution that works (also, only occasionally) is to reboot Tomcat and/or the actual machine (Windows in this case).
  • The URI is definitely available (as confirmed by asking the browser to do the 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();
A: 

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/

Ken
A: 

The only time I've seen something like this happen is when I have a bad connection, or when somebody is closing the socket that I am using from a different thread context.

pfranza
+1  A: 

This usually means that there was a network error, such as a TCP timeout. I would start by placing a sniffer (wireshark) on the connection to see if you can see any problems. If there is a TCP error, you should be able to see it. Also, you can check your router logs, if this is applicable. If wireless is involved anywhere, that is another source for these kind of errors.

AdamC