Bug 63454 - [PATCH] FTP still tries checking or entering directories after a timeout
Summary: [PATCH] FTP still tries checking or entering directories after a timeout
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.10.6
Hardware: All All
: P2 minor (vote)
Target Milestone: 1.10.7
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2019-05-20 21:51 UTC by Eugène Adell
Modified: 2019-06-01 12:31 UTC (History)
1 user (show)



Attachments
patch using FTPConnectionClosedException (3.01 KB, patch)
2019-05-20 22:00 UTC, Eugène Adell
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eugène Adell 2019-05-20 21:51:55 UTC
When an FTP listing takes too much time and ends with a timeout, it is still trying to check its current directory or to enter the next directory. This ends with Ant sending an ugly packet to the FTP server when it should have stopped working in a clean way. Moreover, the Exception logged is too much generic, when we could inform the user of the failure cause.

ANT script for testing :

  <target name="listingWithSymlinks">
    <ftp action="list"
       listing="listingWithSymlinks.txt"
       server="ftp.ietf.org"
       port="21"
       remotedir="/rfc/bcp"
       userid="anonymous"
       password="anonymous" >
       <fileset dir="." defaultexcludes="no" includes="*" />
    </ftp>
  </target>

Exception :
BUILD FAILED/home/eadell/tests/ant-tests/project.xml:23: Unable to scan FTP server:
..
Caused by: Error while communicating with FTP server:
..
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.

Network trace :
20:38:35.916811 IP 185.47.63.113.37166 > 4.31.198.44.21: Flags [P.], seq 4556:4576, ack 17375, win 140, options [nop,nop,TS val 2848957056 ecr 328690075], length 20
E..H..@.@..../?q...,.....7..t........h.....
......i.CWD ../rfc7227.txt

20:38:36.085424 IP 4.31.198.44.21 > 185.47.63.113.37166: Flags [P.], seq 17375:17441, ack 4576, win 227, options [nop,nop,TS val 328690117 ecr 2848957056], length 66
EH.vP%@.-.:)...,./?q....t....7......L......
..i.....421 No transfer timeout (60 seconds): closing control connection

20:38:36.086606 IP 185.47.63.113.37166 > 4.31.198.44.21: Flags [P.], seq 4576:4581, ack 17441, win 140, options [nop,nop,TS val 2848957226 ecr 328690117], length 5
E..9..@.@..../?q...,.....7..t..T...........
...*..i.PWD

20:38:36.089454 IP 4.31.198.44.21 > 185.47.63.113.37166: Flags [F.], seq 17441, ack 4576, win 227, options [nop,nop,TS val 328690119 ecr 2848957056], length 0
EH.4P&@.-.:j...,./?q....t..T.7......f......
..i.....
20:38:36.128258 IP 185.47.63.113.37166 > 4.31.198.44.21: Flags [.], ack 17442, win 140, options [nop,nop,TS val 2848957268 ecr 328690119], length 0
E..4..@.@.."./?q...,.....7..t..U....f......
...T..i.
20:38:36.187110 IP 185.47.63.113.37166 > 4.31.198.44.21: Flags [FP.], seq 4581:5688, ack 17442, win 140, options [nop,nop,TS val 2848957326 ecr 328690119], length 1107
E.....@.@..../?q...,.....7..t..U....(p.....
......i.PWD
PWD
PWD
PWD
PWD
PWD
...
PWD
CDUP
QUIT
Comment 1 Eugène Adell 2019-05-20 22:00:53 UTC
Created attachment 36593 [details]
patch using FTPConnectionClosedException

catch org.apache.commons.net.ftp.FTPConnectionClosedException in the isFunctioningAsDirectory methods, and bring it up to stop further tries. This exception gives knowledge of the closed connection reason, which is clean.
Comment 2 Eugène Adell 2019-05-20 22:10:28 UTC
After applying the patch, I get these results

Exception:
BUILD FAILED
/home/eadell/tests/ant-tests/project.xml:20: Error while communicating with FTP server:
..
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received.  Server closed connection.


Network trace:
00:02:51.994103 IP 185.47.63.113.42105 > 4.31.198.44.21: Flags [P.], seq 4876:4881, ack 18478, win 140, options [nop,nop,TS val 2861213133 ecr 331754100], length 5
E..9G[@.@.0x./?q...,.y......C.'......a.....
......*tPWD

00:02:52.144179 IP 4.31.198.44.21 > 185.47.63.113.42105: Flags [P.], seq 18478:18544, ack 4881, win 227, options [nop,nop,TS val 331754138 ecr 2861213133], length 66
EH.v5.@.-.UM...,./?q...yC.'....3....]3.....
..*.....421 No transfer timeout (60 seconds): closing control connection

00:02:52.144211 IP 4.31.198.44.21 > 185.47.63.113.42105: Flags [F.], seq 18544, ack 4881, win 227, options [nop,nop,TS val 331754138 ecr 2861213133], length 0
EH.45.@.-.U....,./?q...yC.(....3....w......
..*.....
00:02:52.146288 IP 185.47.63.113.42105 > 4.31.198.44.21: Flags [P.], seq 4881:4887, ack 18545, win 140, options [nop,nop,TS val 2861213286 ecr 331754138], length 6
E..:G\@.@.0v./?q...,.y.....3C.(......
.....
...f..*.QUIT


The client can now see the real Exception (421 response), and the network trace looks cleaner without the abnormal concatenation of multiple PWDs + CDUP + QUIT. It just tries a QUIT, which will be resetted by the server.
Comment 3 J.M. (Martijn) Kruithof 2019-06-01 12:31:44 UTC
Thank you very much, patch applied to
https://github.com/apache/ant/commit/382edda47687bf2eec6f65f0f17e29e81b7cf847