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...
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
Depends on:
Reported: 2017-01-26 21:39 UTC by chorsfield
Modified: 2017-05-09 12:54 UTC (History)
5 users (show)

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


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.

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

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.

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.

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