JDK-6213649 : SocketTimeoutException corrupts SSLSocket
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.net.ssl
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2005-01-04
  • Updated: 2011-02-16
  • Resolved: 2005-02-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

A DESCRIPTION OF THE PROBLEM :
When a SocketTimeoutException is thrown over a SSLSocket, the socket gets corrupted. We really need to set the SoTimeout to a short time but this bug prevents us from doing it.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a SSLSocket
Send a request
Set the SoTimeout to a short time
Read bytes

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output should contains the document requested.
ACTUAL -
The output contains undecoded characters after the timeout occurs.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class Bug
{

	public static void main(String[] args)throws Exception
	{
      SSLSocketFactory sslFactory =
          (SSLSocketFactory)SSLSocketFactory.getDefault();
      
      SSLSocket sslSocket =
          (SSLSocket)sslFactory.createSocket("www.verisign.com", 443);
      sslSocket.startHandshake();

      Socket socket = sslSocket;
      //socket = new Socket("www.verisign.com",80);
      
      
      InputStream is = socket.getInputStream();
      OutputStream os = socket.getOutputStream();
                 
      
      String request = "GET / HTTP/1.0\r\n";
      request += "Host: www.verisign.com\r\n";
      request += "Connection: close\r\n\r\n";

      os.write(request.getBytes());

      socket.setSoTimeout(25);
      
      while(true)
      {
         try
         {
            int p = is.read();
            if(p==-1)
            {
               break;
            }
            else
            {
               System.out.print((char)p);
            }
         }
         catch(SocketTimeoutException e)
         {
            System.err.println("Timeout");
         }
      }
      socket.close();
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Comment this line : s.setSoTimeout(25); or increase the timeout !
###@###.### 2005-1-04 05:55:53 GMT

Comments
EVALUATION Duplicate of 4836493. ###@###.### 2005-2-16 19:42:49 GMT
16-02-2005