java.net.SocketException: Software caused connection abort: recv failed [duplicate] java.net.SocketException: Software caused connection abort: recv failed [duplicate] java java

java.net.SocketException: Software caused connection abort: recv failed [duplicate]


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.


This also happens if your TLS client is unable to be authenticate by the server configured to require client authentication.


This error occurs when a connection is closed abruptly (when a TCP connection is reset while there is still data in the send buffer). The condition is very similar to a much more common 'Connection reset by peer'. It can happen sporadically when connecting over the Internet, but also systematically if the timing is right (e.g. with keep-alive connections on localhost).

An HTTP client should just re-open the connection and retry the request. It is important to understand that when a connection is in this state, there is no way out of it other than to close it. Any attempt to send or receive will produce the same error.

Don't use URL.open(), use Apache-Commons HttpClient which has a retry mechanism, connection pooling, keep-alive 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 ...