FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

When using AutoConnect on an FTP server which is not available it waits forever

Open rickvi1 opened this issue 5 years ago • 6 comments

FTP OS: External party - no insights FTP Server: External party - no insights

Computer OS: Azure Function v3/Windows

FluentFTP Version: 32.4.5

When using AutoConnect on an FTP server which is available, everything works as expected. However, as soon as the FTP server becomes unavailable and you try to connect using AutoConnect, it will wait forever (at least 6 hours). I would expect that it throws an exception.

When using just the regular Connect method, I can either connect to the FTP server or when it's not available, it will just throw a SocketException: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." which is something I would expect.

Please do a check on this as it can give really strange behavior in an application.

rickvi1 avatar Sep 22 '20 07:09 rickvi1

But how will the system differentiate between a legit failure to connect and a SocketException indicating the server is unreachable? Should I abort the AutoConnect only if I receive a specific kind of SocketException?

robinrodricks avatar Sep 29 '20 12:09 robinrodricks

When looking at the Source Code of the AutoConnect or especially AutoDetect, it loops trough all possible ways to connect to connect to an FTP server. I would expect that if the client is not able to connect to the FTP server in any of the possible options that are detected with AutoDetect, or if one of the connection attempts is throwing any exception.

My assumption would be that in the AutoDetect method at line 126 for one of the possible combinations it will wait forever (it just keeps trying). Wouldn't it be an idea to have some kind of timeout option which can be configured?

// try to connect
var connected = false;
try {
    conn.Connect();
    connected = true;
    conn.Dispose();
}
catch (Exception ex) {
    conn.Dispose();
}

rickvi1 avatar Oct 01 '20 08:10 rickvi1

There is already a connection timeout of 15 seconds by default.

robinrodricks avatar Oct 01 '20 17:10 robinrodricks

Does this work? FluentFTP.32.4.6_BETA.zip

Btw what do you mean by "not available"? Is it an invalid host, an FTP server that hangs/not responding, in other words, how do I replicate this to test it?

robinrodricks avatar Oct 01 '20 18:10 robinrodricks

Sorry for the delay, I will try to come back on the results tomorrow. By "not available" I mean that the FTP server we are connecting to, is disabled or shut-down. This can be during the night or during (un)expected maintenance.

rickvi1 avatar Oct 08 '20 13:10 rickvi1

Unfortunately no success. I know the FTP server is available from 6am. So I've let my Azure Function trying to connect from 3am, every 20 minutes. However, it did try to connect at 3am and stayed waiting for almost 3 hours (until 6am) and then the connection succeeded. When I would have started trying to connect earlier, it would have been waiting even longer. I cannot see why it is waiting, there is no log output at that moment.

rickvi1 avatar Oct 09 '20 06:10 rickvi1