Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 16185 [details]
iOS test application
When I use a linked cancellation token to cancel a web request stream while its performing a download I am seeing a ObjectDisposedException exception from the SafeSocketHandle class. This exception is thrown inside the mono framework and it is never raised to the calling code, hence I cannot catch it and proceed with my code as my cancelled code never receives the cancellation exception.
It seems that if I do not used linked tokens then the issue is not present, however this code represents a download process were we have the ability to cancel individual items as well as the overall download queue which are done with linked cancellation tokens.
We use the same code in a WPF application and do not see the same issue. It seems that this issue is not present in Microsoft.Net only in Mono.
I have only experienced this issue with a running iPhone or iPad applications.
I can replicate this issue quite often if I perform the cancellation just after it starts downloading the file.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'handle'.
0x22 in System.Net.Sockets.SafeSocketHandle.RegisterForBlockingSyscall at /Users/builder/data/lanes/3234/d8bedd03/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs:83,5 C#
0x1 in System.Net.Sockets.Socket.Receive_internal at /Users/builder/data/lanes/3234/d8bedd03/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1853,5 C#
0x62 in System.Net.Sockets.SocketAsyncWorker.Receive at /Users/builder/data/lanes/3234/d8bedd03/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/SocketAsyncWorker.cs:286,5 C#
0x50 in System.Net.Sockets.SocketAsyncWorker.DispatcherCB at /Users/builder/data/lanes/3234/d8bedd03/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/SocketAsyncWorker.cs:66,5 C#
0x6 in System.Net.Sockets.SocketAsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem at /Users/builder/data/lanes/3234/d8bedd03/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:307,4 C#
So I played with this a little more and have come to the conclusion that the linked tokens is not the issue. The issue is due to the Token.Register. If you look at the code you can see I am calling a Request.About in the Token.Register this is were the framework exception is coming from.
However I would still not expect the request stream to never return in this scenario
Can you take a look at this one?
Would it be possible to get an update to this?
Still waiting to hear what you guys think. Thanks
Sorry for making you wait, I am finishing another fix and I will look into this next.
Thanks for the bug report.
It appears that even .NET throws an WebException some times.
I wrote a repro that was causing ObjectDisposeException on mono and WebException on .NET.
Mono was fixed to also throw WebException in the following pull request.
Until the fix lans on stable I recommend to catch ObjectDisposedException and WebException, after that only WebException will be needed.
Fixed in master 725892b35c29fe919d6e58305ac241f6cbd01018