0 votes
by (140 points)
edited by

Rebex Library: Latest on nuget

My scenario is this. I have a FileTransferClient mClient connecting to an FTP server where the username is set, but the password is incorrect. What I am seeing is that mClient.LoginAsync does not throw. It happily returns with IsAuthenticated = false. Later on I get an UnobservedTaskException in my UnobservedTaskException handler with the following stack trace:

021-11-19 14:47:14.6287 (5156.2) Debug [Initializer] Unexpected logic error [AggregateException] A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
-->[FtpException] Login or password incorrect! (530).
--> at Rebex.Net.Ftp.aqhpm(String p0, String p1, String p2)
--> at Rebex.Net.Ftp.jnmvq(Object p0, Enum p1, Object[] p2)
--> at owtsr.ucnia.nmvkt(Object p0). Please contact

  await m_Client.ConnectAsync(m_Configuration.Host, m_Configuration.Port.Value,(FileTransferMode) m_Configuration.FileTransferType);

  // this is not throwing when there is a login error
  await m_Client.LoginAsync(m_Configuration.User, m_Configuration.Password);

What I am assuming is happening is that your library is not awaiting a task inside LoginAsync. The language in the help documention for LoginAsync seems to imply that this is only beginning an async operation which is not what one would expect from an Async method. Perhaps this is a hold-over from when this was BeginLogin?

"Begins asynchronous Login operation. Authenticates the user to the FTP server."

Lastly, if I replace mClient.LoginAsync with the sync mClient.Login, I get an exception thrown as one would expect. I would expect that awaiting LoginAsync should have the same behavior as the sync method Login.

Could you please have a look at this and let me know if I should be doing something differently.

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (134k points)

Thanks for letting us know about this. It looks like error handling in FileTransferClient.LoginAsync method is wrong. We'll fix this and send you a link to a hotfix. Sorry for the inconvenience!

by (134k points)
I understand. Sadly, there has been one major practical reason for keeping the synchronous code - we still maintain a single code branch for the current mainstream .NET platforms and legacy platforms such as .NET Compact Framework 3.5 or .NET 2.0. We did experiment a bit with asynchronous code on these platforms, but it turned out asynchronous code and legacy platforms was not a good match at all. We will finally drop support for these old platforms in R7.0 next year - then, we will finally be free to gradually rewrite those hundreds of thousands lines of code to eventually reach true asynchronicity.
by (140 points)
I got a similar error. Is there also a possibility to fix it?

Unobserved Task Exception in 'System.Threading.Tasks.Task`1[System.Net.EndPoint]': System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.ObjectDisposedException: The socket has been already closed.
Object name: 'ProxySocket'.
   at Rebex.Net.ProxySocket.ylrwr()
   at Rebex.Net.ProxySocket.Listen(ISocket controlSocket)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
by (134k points)
Hello Floz, which Rebex component do you use, and which operation are you attempting when this occurs? Which Rebex version do you use, and which .NET framework? Is there a way for us to reproduce the error?
by (140 points)
I´m using Rebex.Ftp.Full.5.0.7800 in .NET Framework 4.0
I try to upload a File and it work´s but in this one case there was this exception.

The problem is the Unobserved Task Exception. A normal exception would be ok but this one crashes the whole application.
by (134k points)
Thanks! The problem apparently occurs on .NET 4.0/4.5.x when FTP in active mode times out while waiting for incoming connection. We will fix this in the next release of Rebex FTP/SSL. In the meantime, you can safely work around the issue by observing this particular exception (ObjectDisposedException with ObjectName of "ProxySocket") in UnobservedTaskException event handler and marking it as Observed. For details, see https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler.unobservedtaskexception?view=netframework-4.0