commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weixiang tam <weixiang....@gmail.com>
Subject [Net]
Date Sun, 08 Mar 2009 08:23:50 GMT
Hi All,

Periodically, we are experiencing the FTP client thread is hang when we
upload the file to the FTP server or when we initiate a connection to the
FTP server. See the following thread dump from JBOSS server. It seem like
after the common net FTPClient store the file, it will call the
"FTP.__getReply()" to get the status code, and this should be the point that
causing the thread hang.

There is no Socket connection timeout error be thrown, and the thread just
hang there forever.

*"Uploading file to FTP"*

*Thread: JMS SessionPool Worker-1* : priority:5, demon:true,
threadId:355, threadState:RUNNABLE, threadLockName:null

java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(Unknown Source)
sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source)
sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
sun.nio.cs.StreamDecoder.read(Unknown Source)
java.io.InputStreamReader.read(Unknown Source)
java.io.BufferedReader.fill(Unknown Source)
java.io.BufferedReader.readLine(Unknown Source)
java.io.BufferedReader.readLine(Unknown Source)
*org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)*
org.apache.commons.net.ftp.FTP.getReply(FTP.java:619)
org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1244)
org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:401)
org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1379)
ftp.adaptor.NetCommonsFTPClientManager.putAsciiFile(NetCommonsFTPClientManager.java:444)

I am using the latest common-net release v2.0 and running in Solaris 10,
JRE150_14, jboss AS 4.0.5. The following is the snapshot of the code that
doing the initialization of FTP connection and the part that do the
uploading of file to TP.

As can be seen below, I have set the various set*timeOut method eg
"setDefaultTimeOut", "setSoTimeout", "setDataTimeout" however, none of this
will cause the time out in the connection. Could I know is the way I enable
the timeout correctly set?

//establish connectivity to FTP, set connection timeout to 60s
public NetCommonsFTPClientManager(String host, int port)
    throws FTPException,FTPConnectionException
  {
    int reply = 0;
    try
    {
      _host = host;
      _port = port;
      _ftpClient = new org.apache.commons.net.ftp.FTPClient();

      //test timeout
      _ftpClient.setDefaultTimeout(60 * 1000);
      System.out.println("NetCommon constructor setDefault connection
timeout to 60s");

      _ftpClient.connect(host,port);
      reply = _ftpClient.getReplyCode();
      if(!org.apache.commons.net.ftp.FTPReply.isPositiveCompletion(reply))
      {
        if(_ftpClient.isConnected())
          _ftpClient.disconnect();
      }
      else
      {
        reply = _ftpClient.getReplyCode();
      }

      System.out.println("NetCommon constructor:
connectionTimeout-->"+_ftpClient.getConnectTimeout()+"
defaultTimeout-->"+_ftpClient.getDefaultTimeout()+ " soTimeout-->"
+_ftpClient.getSoTimeout());
    }
    catch(UnknownHostException ex)
    {
      System.out.println("Unknown host exception -->");
      throw new FTPConnectionException(ex.getMessage());
    }
    catch(IOException ex)
    {
      if(_ftpClient.isConnected())
      {
        try{
          _ftpClient.disconnect();
        }
        catch(IOException iex){
        }
      }
      throw new FTPConnectionException(ex.getMessage());
    }
  }

  /**
   * Set the "SoTimeout" and "DataTimeout" to 60 s
   * Save the File to Server with the given InputStream.
   * @param localfile LocalFile as InputStream
   * @param remotefile File name to store on the server.
   * @throws FTPException - thrown upon FTP Error.
   */

  public void putAsciiFile(InputStream localfile, String remotefile)
      throws FTPException
  {
    try
    {
      _ftpClient.setSoTimeout(60 * 1000);
      System.out.println("NetCommonsFTPClientManager.putAsciiFile
setSoTimeout ");

      _ftpClient.setDataTimeout(60 * 1000);
      System.out.println("NetCommonsFTPClientManager.putAsciiFile
setDataTimeout to 60s");

      _ftpClient.storeFile(remotefile,localfile);
    }
    catch(FTPConnectionClosedException ex)
    {
      throw new FTPException(ex.getLocalizedMessage(),
          replyCodeToString(_ftpClient.getReplyCode()));
    }
    catch(IOException fex)
    {
      throw new FTPException(fex.getLocalizedMessage(),
        replyCodeToString(_ftpClient.getReplyCode()));
    }

  }

After doing some search on the internet, I found someone has the similiar
issue as I mentioned, like

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg11641.html
https://issues.apache.org/jira/browse/NET-249

Could I know that is there any work around to resolve the Thread hang issue
after execution of the FTP.__getReply? Or is the way I set the timeout
wrong?

Many thanks
Wei Xiang

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message