Author: sebb Date: Mon Nov 26 10:34:50 2012 New Revision: 1413545 URL: http://svn.apache.org/viewvc?rev=1413545&view=rev Log: NET-46 retrieveFileStream fails randomly or hangs
Modified: commons/proper/net/trunk/src/changes/changes.xml commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Modified: commons/proper/net/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1413545&r1=1413544&r2=1413545&view=diff ============================================================================== --- commons/proper/net/trunk/src/changes/changes.xml (original) +++ commons/proper/net/trunk/src/changes/changes.xml Mon Nov 26 10:34:50 2012 @@ -66,6 +66,9 @@ The <action> type attribute can be add,u This release fixes bugs and adds some new functionality (see below). It is binary compatible with previous releases. "> + <action issue="NET-46" dev="sebb" type="fix"> + retrieveFileStream fails randomly or hangs + </action> <action issue="NET-485" dev="sebb" type="fix"> Remove unnecessary Base64 methods. </action> Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1413545&r1=1413544&r2=1413545&view=diff ============================================================================== --- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original) +++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Mon Nov 26 10:34:50 2012 @@ -773,6 +773,11 @@ implements Configurable server.setSoTimeout(__dataTimeout); } socket = server.accept(); + + // Ensure the timeout is set before any commands are issued on the new socket + if (__dataTimeout >= 0) { + socket.setSoTimeout(__dataTimeout); + } } finally { server.close(); } @@ -808,6 +813,15 @@ implements Configurable if (__passiveLocalHost != null) { socket.bind(new InetSocketAddress(__passiveLocalHost, 0)); } + + // For now, let's just use the data timeout value for waiting for + // the data connection. It may be desirable to let this be a + // separately configurable value. In any case, we really want + // to allow preventing the accept from blocking indefinitely. + if (__dataTimeout >= 0) { + socket.setSoTimeout(__dataTimeout); + } + socket.connect(new InetSocketAddress(__passiveHost, __passivePort), connectTimeout); if ((__restartOffset > 0) && !restart(__restartOffset)) { @@ -831,10 +845,6 @@ implements Configurable " is not same as server " + getRemoteAddress().getHostAddress()); } - if (__dataTimeout >= 0) { - socket.setSoTimeout(__dataTimeout); - } - if ( __bufferSize > 0 ) { socket.setReceiveBufferSize(__bufferSize); socket.setSendBufferSize(__bufferSize);