Bug 5315 - ThreadStateException "Unable to reset abort because no abort was requested" while aborting HttpWebRequest
Summary: ThreadStateException "Unable to reset abort because no abort was requested" w...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.2
Hardware: PC Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Gonzalo Paniagua Javier
URL:
Depends on:
Blocks:
 
Reported: 2012-05-24 21:37 UTC by Matt Crocker
Modified: 2012-07-13 18:01 UTC (History)
4 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 Matt Crocker 2012-05-24 21:37:57 UTC
Sorry, this won't be a useful bug report, but here goes:

I received the following exception from a MonoTouch 5.2.11 app running on an iPhone with iOS 5.1.1: ThreadStateException "Unable to reset abort because no abort was requested"

The crash log did not include a full stack trace, but shows that the phone was in poor network conditions and had been repeatedly aborting HttpWebRequests after a timeout period.

Since there are no ResetAborts in our app I think the only realistic source is  https://github.com/mono/mono/blob/mono-2-10/mcs/class/System/System.Net.Sockets/Socket_2_1.cs#L1239
which is triggered if you abort a webrequest while it is waiting for the socket to connect.

This doesn't make much sense, since a ThreadAbortException just happened, and thread state really should be aborted.

At this point I'm out of ideas. Am not sure how to repro, or how I might work around the problem. 

The closest I have to a theory is that WebConnection.Abort doesn't appear to be thread-safe. WebConnection.Close locks "this" before closing the socket (https://github.com/mono/mono/blob/mono-2-10/mcs/class/System/System.Net/WebConnection.cs#L1058), but WebConnection.Connect locks "socketLock" while also closing the socket (https://github.com/mono/mono/blob/mono-2-10/mcs/class/System/System.Net/WebConnection.cs#L134). In theory socket.Dispose() could be called twice, but am not sure how that would result in a ThreadStateException 

Thoughts?
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-05-28 17:20:47 UTC
Gonzalo, this looks like your area.
Comment 2 Gonzalo Paniagua Javier 2012-06-13 17:35:42 UTC
Not much here that I can use. But here goes another theory: it could be a problem in the runtime thread-related code when setting and resetting the thread status.
Comment 3 Miguel de Icaza [MSFT] 2012-07-13 18:01:50 UTC
We have implemented a milder way of closing pending connections that does not involve Thread.Abort.

Fix is now on master/mono-10 and mobile-master, and making its way through QA for both MonoTouch and Mono for Android.