Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-661

FTPSClient hang java.net.SocketInputStream.socketRead0 while doing SSL Handshake - Socket timeout not set

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.6
    • Fix Version/s: None
    • Component/s: FTP
    • Environment:

      Description

      In a lab with unstable connection we have our FTP client hanging forever (e.g. 36 hours -> base on our linux kernel configuration)

      java.lang.Thread.State: RUNNABLE
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
      at java.net.SocketInputStream.read(SocketInputStream.java:171)
      at java.net.SocketInputStream.read(SocketInputStream.java:141)
      at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
      at sun.security.ssl.InputRecord.read(InputRecord.java:503)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
      locked <0x00000000ae243608> (a java.lang.Object)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
      locked <0x00000000ae243620> (a java.lang.Object)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
      at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:289)
      at org.apache.commons.net.ftp.FTPSClient.connectAction(FTPSClient.java:220)
      at org.apache.commons.net.SocketClient._connect(SocketClient.java:244)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
      ...

      our code

      final FTPSClient client = new FTPSClient("TLSv1.2", true);
      // load the trust store& key store
      client.setDataTimeout(1000);
      client.setControlKeepAliveReplyTimeout(1000);
      client.setControlKeepAliveTimeout(1000);
      client.setDefaultTimeout(1000);
      client.setConnectTimeout(1000);
      client.connect(host, port); // hang randomly
      client.setSoLinger(true, 10); // cannot be call before, socket is null
      reply = client.getReplyCode();

      After looking at the FTP, FTPSClient code and reading on internet I realize that in the case of an implicit connection the Socket is initialized with So timeout of 0 because "connectAction()" is overwritten

      Socket.java

      protected void connectAction() throws IOException
          socket.setSoTimeout(timeout);
          input = socket.getInputStream();
          output = socket.getOutputStream(); }

      FTPSClient.java

      @Override

      protected void connectAction() throws IOException {

          // Implicit mode.
           if (isImplicit) {
               sslNegotiation(); // hangs at java.net.SocketInputStream.socketRead0(Native Method)
           }
           super.connectAction(); // setSoTimeout will be set here - but too late
           // Explicit mode.
           if (!isImplicit)
      Unknown macro: {        execAUTH();      }
      }

      So workaround for now is to overwrite FTPSClient-> connectAction()

      new FTPSClient(...)

      Unknown macro: { @Override protected void _connectAction_() throws IOException   Unknown macro}

      };

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              danalain Dany Alain
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: