Bug 51804 - AndroidClientHandler has unobserved aggregate exception and Java.IO Exceptions in place of WebException
Summary: AndroidClientHandler has unobserved aggregate exception and Java.IO Exception...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: 15.2
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-01-26 21:39 UTC by chorsfield
Modified: 2017-05-09 12:54 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description chorsfield 2017-01-26 21:39:54 UTC
This bug is in Master and not C8 or C9

This change in Master resulted in some issues.
https://github.com/xamarin/xamarin-android/commit/0c3597869bc4493895e755bda8a26f778e4fe9e0

Problems:
This code now started having unobserved aggregate exception been thrown. 
Started throwing Java.IO.IOException in place of WebException

Code in AndroidClientHandler SendAsync Call.

This Code:
await Task.WhenAny (
                httpConnection.ConnectAsync (),
                Task.Run (()=> { cancellationToken.WaitHandle.WaitOne(); }))
                .ConfigureAwait(false);


The problem here is that Task.WhenAny this returns Task<Task> not a Task this orphans the task it is not waited on. 
Before this change it was ok the code did not result in these unobserved aggregate exception 

Simple test with await await Task.WhenAny (httpConnection.ConnectAsync ()...
Seems to resolve the issue.

Thanks
Comment 1 chorsfield 2017-01-28 01:56:27 UTC
Note the solution of double "await await Task.WhenAny" solves most the issues, but the core problem with WhenAny it only allows exceptions from the first task to finish to be observed. The others are lost if you don't handle them and wont materialize to the caller and be an issue.

Like the case here when the cancelation token is envoked this cause the WhenAny to exit on the cancellation and also causes the delegate that calls Disconnect. That second delegate call on Disconnect causes httpConnection.ConnectAsync to throw a socket disconnect exception that I lost as an un observed exception. This case should probably also be addressed.
Comment 2 Marek Habersack 2017-03-07 12:46:10 UTC
PR opened: https://github.com/xamarin/xamarin-android/pull/472
Comment 3 Marek Habersack 2017-03-09 20:38:18 UTC
Fixed in

   xamarin-android/master, commit 36d7e73de6e9480ffa81a19adb990f912f36bd38
Comment 4 Roshan Mankani 2017-05-09 12:54:59 UTC
Hello All,
Can anyone provide proper steps or description with expected condition, for verifying this bug.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Note You need to log in before you can comment on or make changes to this bug.