JDK-8009650 : HttpClient available() check throws SocketException when connection has been closed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u38,7u40,8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-03-07
  • Updated: 2013-06-27
  • Resolved: 2013-03-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6u60Fixed 7u40Fixed 8 b84Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
The HttpClient.available() method is used to check that a cached connection is still open. In order to do this we temporarily set the socket timeout to 1ms and then attempt to read. If we hit the socket timeout we know that the socket was open. If read returns -1 we know it is closed.

Unfortunately the fact that the get/setSoTimeout()'s can themselves throw a SocketException was overlooked.

The solution to this problem is to wrap the entire try/catch/finally block (we call setSoTimeout in the finally) in a try/catch (SocketException) which will catch the potential SocketException from the try and finally blocks.
SQE Verified

The exception is: Caused by: java.net.SocketException: Socket Closed at java.net.PlainSocketImpl.getOption(PlainSocketImpl.java:286) at java.net.Socket.getSoTimeout(Socket.java:1032) at sun.net.www.http.HttpClient.available(HttpClient.java:356) at sun.net.www.http.HttpClient.New(HttpClient.java:273) at sun.net.www.http.HttpClient.New(HttpClient.java:310) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:987) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1031) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1410) This issue also seems to affect JDK 6, and it appears that other people have also run into this: http://stackoverflow.com/questions/14270311/rather-mysterious-socketexception-with-java-1-6-on-centos-4

caused by 7199862