Thanks for this Stuart, do you happen to have a reference to the bug you filed on the Oracle site?

    -Rob

On 02/03/13 08:55, Stuart Douglas wrote:
Seeing as the patch appears to have been stripped here it is inline:

diff -r 2eb3ac105b7f src/share/classes/sun/net/www/http/HttpClient.java
--- a/src/share/classes/sun/net/www/http/HttpClient.java        Wed Feb 27 
21:05:09 2013 -0800
+++ b/src/share/classes/sun/net/www/http/HttpClient.java        Sat Mar 02 
19:06:26 2013 +1100
@@ -362,13 +362,15 @@
protected synchronized boolean available() throws IOException {
          boolean available = true;
-        int old = serverSocket.getSoTimeout();
-        serverSocket.setSoTimeout(1);
-        BufferedInputStream tmpbuf =
-            new BufferedInputStream(serverSocket.getInputStream());
+        int old = -1;
PlatformLogger logger = HttpURLConnection.getHttpLogger();
          try {
+            old = serverSocket.getSoTimeout();
+            serverSocket.setSoTimeout(1);
+
+            BufferedInputStream tmpbuf =
+                    new BufferedInputStream(serverSocket.getInputStream());
              int r = tmpbuf.read();
              if (r == -1) {
                  if (logger.isLoggable(PlatformLogger.FINEST)) {
@@ -382,8 +384,17 @@
                  logger.finest("HttpClient.available(): " +
                      "SocketTimeout: its available");
              }
+        } catch (SocketException e) {
+            if (logger.isLoggable(PlatformLogger.FINEST)) {
+                logger.finest("HttpClient.available(): " +
+                        "SocketException: not available");
+            }
+            available = false;
+            old = -1; //we don't want to call setSoTimeout, as that will throw 
an exception
          } finally {
-            serverSocket.setSoTimeout(old);
+            if(old != -1) {
+                serverSocket.setSoTimeout(old);
+            }
          }
          return available;
      }


----- Original Message -----
From: "Chris Hegarty" <chris.hega...@oracle.com>
To: "Stuart Douglas" <sdoug...@redhat.com>
Cc: "Alessio Soldano" <asold...@redhat.com>, "OpenJDK Network Dev list" 
<net-dev@openjdk.java.net>, "Rob McKenna"
<rob.mcke...@oracle.com>
Sent: Saturday, 2 March, 2013 7:37:30 PM
Subject: Re: OpenJDK HTTP Client Bug

[bcc'ing off jdk7-...@openjdk.java.net, and including
net-dev@openjdk.java.net]

Hi Stuart,

Thanks for reporting this issue.

It does indeed look like a regression/side-effect of that recent
change.
There is no sign of your attached patch, maybe it got stripped by
mailman. You can probably just post it inline.

Thanks,
-Chris.

On 03/02/2013 08:18 AM, Stuart Douglas wrote:
Hello everyone,

(This is my first post to this list, so I am not 100% sure if this
is
the right place).

I have run into a bug in the JDK HttpClient that was caused by a
recent
commit:

http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/diff/e6dc1d9bc70b/src/share/classes/sun/net/www/http/HttpClient.java


The method sun.net.www.http.HttpClient#available() can throw
java.net.SocketException, which can cause the creation of the
HttpClient
to fail. This will happen if there is a connection in the cache
that has
timed out and the socket has been closed.

I have attached a small patch that should resolve the problem,
although
due to its intermittent nature I have not been able to verify with
100%
certainty.


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


I attempted to file a bug for this on the Oracle website, however
as far
as I can tell it was ignored.

Stuart


Reply via email to