No connection timeout for sun SSLSocketImpl, potential bug?
<p>Recently we met SocketTimeoutException when the client application connecting to server. The client app utilized Axis1.4 as the SOAP engine. We already set the connection timeout and read timeout as 20 seconds for socket, but it looks like the connection timeout value doesn't work. </p>

<p>After digging into the socket creation in JDK, the socket factory used is <strong>sun.security.ssl.SSLSocketFactoryImpl</strong>, and the socket impl is <strong>sun.security.ssl.SSLSocketImpl</strong>. The problem is in the initialization of SSLSocketImpl, it hard-coded the connection timeout value as 0, that's mean there's no timeout:</p>

<pre><code>SSLSocketImpl(SSLContextImpl context, InetAddress host, int port)
        throws IOException {
    super();
    init(context, false);
    SocketAddress socketAddress = new InetSocketAddress(host, port);
    connect(socketAddress, 0);
}
</code></pre>

<p>And the connection method is:</p>

<pre><code> /**
 * Connects this socket to the server with a specified timeout
 * value.
 *
 * This method is either called on an unconnected SSLSocketImpl by the
 * application, or it is called in the constructor of a regular
 * SSLSocketImpl. If we are layering on top on another socket, then
 * this method should not be called, because we assume that the
 * underlying socket is already connected by the time it is passed to
 * us.
 *
 * @param   endpoint the &lt;code&gt;SocketAddress&lt;/code&gt;
 * @param   timeout  the timeout value to be used, 0 is no timeout
 * @throws  IOException if an error occurs during the connection
 * @throws  SocketTimeoutException if timeout expires before connecting
 */
public void connect(SocketAddress endpoint, int timeout)
        throws IOException {

    if (self != this) {
        throw new SocketException("Already connected");
    }

    if (!(endpoint instanceof InetSocketAddress)) {
        throw new SocketException(
                              "Cannot handle non-Inet socket addresses.");
    }

    super.connect(endpoint, timeout);
    doneConnect();
}
</code></pre>

<p>Why sun's implementation hard-coded 0? Is this a bug? From this to see the application need handle timeout by itself, this is weird. </p>