TransferClient.LoginAsync() causes an UnobservedTaskException

0 votes
asked 6 days ago by jon.reis (140 points)
edited 6 days ago by jon.reis

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
answered 6 days ago by Lukas Pokorny (126,870 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!

commented 6 days ago by jon.reis (140 points)
No worries. Thanks for taking a look at it.
commented 6 days ago by Lukas Pokorny (126,870 points)
I just sent a link to a pre-release build to your e-mail, please give it a try and let me know whether it resolves the issue.
commented 6 days ago by jon.reis (140 points)
Thank you for the quick turnaround Lukas. I can confirm this fixes the issue. I get the exception while awaiting LoginAsync()
commented 6 days ago by jon.reis (140 points)
Would it be possible for you to add this to nuget as a pre-release package so we can release a version of our product with the fix?
commented 5 days ago by Lukas Pokorny (126,870 points)
Thanks for testing! We plan to publish the next release tomorrow, so hopefully a pre-release won't be needed.
commented 4 days ago by Lukas Pokorny (126,870 points)
commented 3 days ago by jon.reis (140 points)
Thank you for the fix Lukas. Much appreciated.
I must admit though that I am a little taken that these calls are not truly asynchronous.
...