FTP Download Abort & Socket CLOSE_WAIT

0 votes
asked Dec 8, 2019 by lanopk (980 points)
edited Dec 8, 2019 by lanopk

In my program, I download one of the files from FTP.
If I do Ftp.Abort or Ftp.Disconnect during the download, the Data Socket is in the CLOSE_WAIT state.
When I received all of the file contents, the Socket was all cleaned up.
If this happens frequently, the data port will run out and no more connections can be made.
How do I solve this problem?

Thank you.

Rebex Version : 2019 R4

test 1)
ftp.GetFile ();
// not download all
ftp.Abort ();
-> CLOSE_WAIT

test2 2)
ftp.GetFile ();
// not download all
ftp.Disconnect ();
-> CLOSE_WAIT

test3 3)
stream = ftp.GetDownloadStream ();
// not download all
stream.Close ();
-> CLOSE_WAIT

Applies to: Rebex FTP/SSL

2 Answers

0 votes
answered Dec 9, 2019 by Lukas Pokorny (106,330 points)

Transfer aborting in FTP is surprisingly complex due to numerous workaround for dozens of different server behaviors. This might be a client-side issue, but in order to be able to look into it, we first need to know how your server behaves. Could you please create a communication log of those tests and either post it here or mail it to us for analysis? Thanks!

commented Dec 9, 2019 by lanopk (980 points)
I have mailed you an FTP LOG file.
For reference, Close_wait occurs as shown below.
C: \ Users \ lanop> netstat -ano | find "192.168.0.8" | find "CLOSE_WAIT"
   TCP 192.168.0.13:9988 192.168.0.8:55538 CLOSE_WAIT 2192
   TCP 192.168.0.13:9990 192.168.0.8:55536 CLOSE_WAIT 2192
   TCP 192.168.0.13:9992 192.168.0.8:55539 CLOSE_WAIT 2192
commented Dec 9, 2019 by Lukas Pokorny (106,330 points)
Thanks for the log! Apparently, in some abort scenarios, such as yours, the data connection is not properly closed from the client side, leading to sockets left in CLOSE_WAIT state. I just sent a link to a hotfix to your e-mail - please give it a try and let me know whether it solves the issue.
commented Dec 10, 2019 by lanopk (980 points)
After testing, your hot-fix works perfectly without DoNotSendAbort flag.
Thank you.
commented Dec 10, 2019 by Lukas Pokorny (106,330 points)
Thanks for testing! We'll include this fix in the next official release soon.
0 votes
answered Dec 9, 2019 by lanopk (980 points)

I've found a way to fix the problem in the current state.

Settings.DoNotSendAbort = true;

Setting this flag solves the problem.
However, attach the log you want.
If FTP behaves like an attached log, three CLOSE_WAITs appear to me.

The log content is too large to fit here.
I will send it by email.

Thank you.

commented Dec 9, 2019 by Lukas Pokorny (106,330 points)
With this option, instead of sending the ABOR command as specified by the FTP protocol, the client just closes the receiving socket. That does work around the issue that caused data socket to be left in CLOSE_WAIT state. However, some FTP servers might not like this option.
...