United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8009650 HttpClient available() check throws SocketException when connection has been closed
JDK-8009650 : HttpClient available() check throws SocketException when connection has been closed

Details
Type:
Bug
Submit Date:
2013-03-07
Status:
Closed
Updated Date:
2013-06-22
Project Name:
JDK
Resolved Date:
2013-03-14
Component:
core-libs
OS:
Sub-Component:
java.net
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u38,7u40,8
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Duplicate:
Relates:

Sub Tasks

Description
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.
                                    

Comments
caused by 7199862
                                     
2013-03-08
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

                                     
2013-03-08
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/f5c85c0a9af0
User:  robm
Date:  2013-03-14 00:21:40 +0000

                                     
2013-03-14
SQE Verified
                                     
2013-03-16
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/f5c85c0a9af0
User:  lana
Date:  2013-04-02 17:50:39 +0000

                                     
2013-04-02



Hardware and Software, Engineered to Work Together