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 ()
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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

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.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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.