Menu

#1058 Active FTP hangs if server does not open data connection

closed-fixed
ftp (93)
5
2013-06-21
2011-10-27
No

Working with libcurl version 7.22.0

An active FTP connection is setup with multi interface. Sometimes it is just not possible for FTP server to connect to the port given by the client with PORT or EPRT command. Server could send 425 Can't open data connection or be just dead in the middle of transaction.

Killing the executable (and having a coredump) shows that AllowServerConnect function just looks for notifications in the data connection however control connection should also be observed to get errors like the ones described above.

Server log:

(192.168.0.90)> STOR cmd_input.txt
(192.168.0.90)> 150 Opening data channel for file transfer.
(192.168.0.90)> 425 Can't open data connection.
(192.168.0.90)> 421 Connection timed out.

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2011-10-27

    Hm, this does indeed warrant some kind of fix.

    Have you looked into producing a test case that repeats this case?

     
  • Gokhan Sengun

    Gokhan Sengun - 2011-10-27

    Hi Daniel,

    Test case could be easily written. When an active FTP connection is made, Server side socket stays in TIME_WAIT state for the remote port X which is used in the previous data connection between the client and the server. If another FTP data connection is to be established before Server socket times out (default to 2 minutes), server fails to connect to the port opened by FTP client.

    So repeating triggering two active FTP downloads/uploads, the second connection should exhibit the behaviour.

    Attaching the test code.

     
  • Gokhan Sengun

    Gokhan Sengun - 2011-10-27

    File to repeat the problem

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-10-27

    Your test code works fine for me, doing the 3 consecutive transfers from my local ftp server. Repeatedly. on Linux...

     
  • Gokhan Sengun

    Gokhan Sengun - 2011-10-29

    The test code works fine for me too with a Linux FTP host running on the local machine. Original problem was created with a code using libcurl running on Linux machine which connects to an FTP server running on a Windows host.

    I guess Linux FTP server gets the last ACK from libcurl and immediately set the port's state to "CLOSED" without putting it on "TIME_WAIT" and wait enough time (2 minutes) to make sure that the remote party stopped playing the TCP/IP game.

    I again guess that my Filezilla FTP server running on Windows is not clever enough to wait for the last ACK from the FTP client and therefore windows TCP stack puts the port in "TIME_WAIT" state to make sure nobody else use this port to assure reliability. So this seems clearly Filezilla Server's bug if not Windows :-)

    Regardless of the rootcause of the problem, I believe libcurl should no longer wait server to connect from data port if server sent a 4xx command from the control channel.

    Thanks for your attention on this Daniel!

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-10-29

    Yang Tse has started working on adjusting the test FTP server code to make it able to run exactly your case and once we have a test case in the curl test suite that can repeat this case I intend to work on it.

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-12-20
    • status: open --> closed-fixed
     
  • Daniel Stenberg

    Daniel Stenberg - 2011-12-20

    Thanks for the report, this problem is now fixed in the git repository.

    To try it out, you either checkout/update your git clone: http://curl.haxx.se/source.html

    or you try tomorrow's daily snapshot: http://curl.haxx.se/snapshots/