Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCastException thrown after TimerQueueTimer.CallCallback #81211

Closed
tipa opened this issue Jan 26, 2023 · 44 comments
Closed

InvalidCastException thrown after TimerQueueTimer.CallCallback #81211

tipa opened this issue Jan 26, 2023 · 44 comments
Assignees
Milestone

Comments

@tipa
Copy link

tipa commented Jan 26, 2023

Description

After upgrading my iOS app from classic Xamarin.iOS to .NET7 I started observing frequent InvalidCastExeptions in my crash reporting tool (AppCenter). I haven't changed much dependency-wise and I am unable to reproduce this locally.

Reproduction Steps

Unfortunately, I don't know what part of my code causes this behavior.
For the first stack trace, I assume that my code (or some dependencies code) is creating a CancellationTokenSource with a delay parameter.
For the second stack trace below, I assume that some call to Task.Delay is causing the crash.

Expected behavior

No crash :)

Actual behavior

SIGABRT: Arg_InvalidCastException

System.Threading.CancellationTokenSource.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

((CancellationTokenSource)state!).NotifyCancellation(throwOnFirstException: false); // skip ThrowIfDisposed() check in Cancel()

SIGABRT: Arg_InvalidCastException

System.Threading.Tasks.Task.DelayPromise.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

private static void TimerCallback(object? state) => ((DelayPromise)state!).CompleteTimedOut();

Both crashes originate from here:


The "_state" variable is nullable, and based on the reports, the crashes are caused by the variable to be indeed null.

Regression?

I did not see those crashes when using "old" Xamarin.iOS

Known Workarounds

No response

Configuration

.net7-ios
happens on various iPhone models and iOS versions

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 26, 2023
@ghost
Copy link

ghost commented Jan 26, 2023

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

After upgrading my iOS app from classic Xamarin.iOS to .NET7 I started observing frequent InvalidCastExeptions in my crash reporting tool (AppCenter). I haven't changed much dependency-wise and I am unable to reproduce this locally.

Reproduction Steps

Unfortunately, I don't know what part of my code causes this behavior.
For the first stack trace, I assume that my code (or some dependencies code) is creating a CancellationTokenSource with a delay parameter.
For the second stack trace below, I assume that some call to Task.Delay is causing the crash.

Expected behavior

No crash :)

Actual behavior

System.Threading.CancellationTokenSource.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

((CancellationTokenSource)state!).NotifyCancellation(throwOnFirstException: false); // skip ThrowIfDisposed() check in Cancel()

System.Threading.Tasks.Task.DelayPromise.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

private static void TimerCallback(object? state) => ((DelayPromise)state!).CompleteTimedOut();

Both crashes originate from here:


The "_state" variable is nullable, and based on the reports, the crashes are caused by the variable to be indeed null.

Regression?

I did not see those crashes when using "old" Xamarin.iOS

Known Workarounds

No response

Configuration

.net7-ios
happens on various iPhone models and iOS versions

Other information

No response

Author: tipa
Assignees: -
Labels:

area-System.Threading, untriaged

Milestone: -

@ghost
Copy link

ghost commented Jan 27, 2023

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

After upgrading my iOS app from classic Xamarin.iOS to .NET7 I started observing frequent InvalidCastExeptions in my crash reporting tool (AppCenter). I haven't changed much dependency-wise and I am unable to reproduce this locally.

Reproduction Steps

Unfortunately, I don't know what part of my code causes this behavior.
For the first stack trace, I assume that my code (or some dependencies code) is creating a CancellationTokenSource with a delay parameter.
For the second stack trace below, I assume that some call to Task.Delay is causing the crash.

Expected behavior

No crash :)

Actual behavior

SIGABRT: Arg_InvalidCastException

System.Threading.CancellationTokenSource.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

((CancellationTokenSource)state!).NotifyCancellation(throwOnFirstException: false); // skip ThrowIfDisposed() check in Cancel()

SIGABRT: Arg_InvalidCastException

System.Threading.Tasks.Task.DelayPromise.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )

this is here:

private static void TimerCallback(object? state) => ((DelayPromise)state!).CompleteTimedOut();

Both crashes originate from here:


The "_state" variable is nullable, and based on the reports, the crashes are caused by the variable to be indeed null.

Regression?

I did not see those crashes when using "old" Xamarin.iOS

Known Workarounds

No response

Configuration

.net7-ios
happens on various iPhone models and iOS versions

Other information

No response

Author: tipa
Assignees: -
Labels:

area-System.Threading, untriaged, area-Threading-mono, os-ios

Milestone: -

@akoeplinger
Copy link
Member

/cc @lambdageek

@lambdageek
Copy link
Member

Weird. Both CancellationTokenSource and DelayTimer pass this for the state argument of TimerQueueTimer.
So the state passed to the callback should be non-NULL, and the cast from object to the respective types should succeed.

Maybe there's a GC hole somewhere?

@lambdageek
Copy link
Member

@tipa when you try to reproduce the issue locally, are you trying it in a simulator or on a device?

@tipa
Copy link
Author

tipa commented Jan 27, 2023

@lambdageek I tested my apps on both simulator and physical device numerous times - I was never able to observe this myself (edit: I now am, using a TestFlight app and repeatedly starting it).
The crash is not super-common, but also not super-rare. I updated both my apps ~1 week ago.
Since then, one of the two apps that I am observing this is installed on ~5000 devices with around 2000 app sessions per day and the crash occurred 7 times (on 7 different devices).
And the other app is installed on ~1000 devices with around 300 app sessions per day and the crash occurred 3 times (on 2 different devices).

@tipa
Copy link
Author

tipa commented Jan 31, 2023

I am also seeing a lot of these exceptions (220 crashes from 80 devices , all originating from DelayPromise) in an app that does a lot of (concurrent) network calls. Maybe the HttpClient uses this under the hood...

@tipa
Copy link
Author

tipa commented Feb 15, 2023

A lot more crash reports have been accumulated in the meantime. I expect the real number to be even higher because AppCenter only seems to report a fraction of the real crashes.
I was also able to reproduce this now in a TestFlight app. it appears to happen when the app is of spawning a few (~10) new tasks and letting them do some concurrent work (getting credentials from the key chain, doing HTTP requests, deserialize JSON (using System.Text.Json), etc).
The other app I mentioned above (now 322 crashes in the last 30 days) does something similar.

I observed a crash with a similar behavior on Android (see here + fix here), maybe this is from a similar cause?

Additionally, I also started seeing these stack traces::

SIGABRT: Object reference not set to an instance of an object

System.AggregateException..ctor(String , List`1 )
System.Threading.Tasks.TaskExceptionHolder.Finalize()

SIGABRT: Arg_ArrayTypeMismatchException

System.AggregateException..ctor(String , List`1 )
System.Threading.Tasks.TaskExceptionHolder.Finalize()

Maybe I should have opened this bug in the xamarin-macios repo?

@steveisok
Copy link
Member

Maybe I should have opened this bug in the xamarin-macios repo?

No, it does look like a runtime issue, so you have the right place.

@steveisok steveisok added this to the 8.0.0 milestone Feb 15, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Feb 15, 2023
@tipa
Copy link
Author

tipa commented Feb 16, 2023

Ok, I was just wondering because the same app runs without much issues on Android, I am only observing them on iOS at the moment.
I was able to collect a lot of stack traces now and can share them if needed.

@fabEps
Copy link

fabEps commented Mar 20, 2023

Same issue here with .net MAUI iOS.
2 cases where this happens 1–2 hours after app went to background.

@gvs55
Copy link

gvs55 commented Mar 22, 2023

Same here. .net 7 MAUI iOS. Starting to see these in azure monitor.

@michaldobrodenka
Copy link

Same problem here - workaround - turn off llvm optimisations

@suchithm
Copy link

Same issue, .Net iOS(Native), llvm optimisation is already tuned off.

SIGABRT: Arg_InvalidCastException
System.Threading.CancellationTokenSource.TimerCallback(Object )
System.Threading.TimerQueueTimer.CallCallback(Boolean )
System.Threading.TimerQueueTimer.Fire(Boolean )
System.Threading.TimerQueue.FireNextTimers()
System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )
System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
System.Threading.Thread.StartCallback()

@durandt
Copy link

durandt commented Aug 16, 2023

I can confirm:

  • this happening in my MAUI application
  • this seemingly only impacting iOS Release builds
  • this having to do with a CancellationTokenSource created a while ago, and crash happening after the app has been in background for some time
  • AppCenter.ms losing most crash reports on iOS (worse, then crash reports don't even appear in the device logs)

In my case though I was using an old CancellationTokenSource in a case where i should not have so I could easily fix this by fixing how I use CancellationTokenSource.

@suchithm
Copy link

@durandt Can you please elaborate on how exactly you fix this issue ?

@durandt
Copy link

durandt commented Aug 28, 2023

@durandt Can you please elaborate on how exactly you fix this issue ?

@suchithm I think I was over-optimistic. I could find which piece of code was crashing and there was I risk that code would sometimes have retained an old CancellationTokenSource and maybe call Cancel() on it. I fixed that and it seems that the crash happen less frequently in this scenario but they still do happen.

I have also reported this issue to the AppCenter folks as it seems this crash gets underreported. (something in the AppCenter libs may be silencing the crash, when it occurred I could not find the crashlog file on the iOS device).

@lambdageek
Copy link
Member

lambdageek commented Aug 29, 2023

Update I don't think this is related. I think most of the time for beforefieldinit we run the cctor when we patch the method's ldsfda patch

@vargaz I'm looking at

/*
* Check if the class given by sreg1 was inited, if not, call
* mono_generic_class_init_trampoline () though a trampoline.
* Since the trampoline saves all registers, this doesn't clobber
* any registers.
*/
MINI_OP(OP_GENERIC_CLASS_INIT, "generic_class_init", NONE, IREG, NONE)

And at the commit from 2015 that removed generic class trampolines mono/mono@bcf4f87

What guarantees now that OP_GENERIC_CLASS_INIT doesn't clobber any registers?

@tipa
Copy link
Author

tipa commented Sep 11, 2023

I sincerely hope that this issue will be fixed as planned with the release of .NET 8 (and not moved to the .NET 9 or Future milestone like so many other issues I've reported)- it is by far the top source of crashes in my apps.
As I've indicated before, I seems to happen primarily when there are a lot of HTTP requests sent out in parallel.

@divil5000
Copy link

We are also encountering this problem since "upgrading" from Xamarin to net7-ios. We have an install base of tens of thousands, and are seeing dozens of these reports coming in each day, having fully deployed our latest and greatest version. Rolling back would be extremely difficult so this puts us in an unfortunate position since the whole app crashes. Come on Microsoft, a little support?

MonoTouch: 16.5.0
iOS: 16.6.1
Hardware: iPhone14,2
System.InvalidCastException: Arg_InvalidCastException
at System.Threading.CancellationTokenSource.TimerCallback(Object )
at System.Threading.TimerQueueTimer.CallCallback(Boolean )
at System.Threading.TimerQueueTimer.Fire(Boolean )
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object , Thread )
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()

@michaldobrodenka
Copy link

@divil5000 just for Info, do you have llvm turned on?

@divil5000
Copy link

What does your repro look like at the moment? We're only seeing a few exceptions per thousands of runs of our software in the wild. I can tell you the following, though:

  • We only use CancellationTokenSource (directly) when configuring an HttpClient, so that's where I would focus testing
  • The relative lack of complaints coming back from customers makes me think this is happening when our app has been backgrounded by iOS

If I were trying to develop a repro I would be firing off lots of HttpClient requests for large files, all with cancellation triggered after a certain timeout (we always use 20 seconds in case that helps focus efforts) then pressing the Home button on the iPhone hardware in question to see if it reproduces after a little while.

@lambdageek
Copy link
Member

lambdageek commented Sep 27, 2023

What does your repro look like at the moment? We're only seeing a few exceptions per thousands of runs of our software in the wild. I can tell you the following, though:

  • We only use CancellationTokenSource (directly) when configuring an HttpClient, so that's where I would focus testing
  • The relative lack of complaints coming back from customers makes me think this is happening when our app has been backgrounded by iOS

If I were trying to develop a repro I would be firing off lots of HttpClient requests for large files, all with cancellation triggered after a certain timeout (we always use 20 seconds in case that helps focus efforts) then pressing the Home button on the iPhone hardware in question to see if it reproduces after a little while.

Thanks @divil5000 that's pretty helpful! I've been focusing on this as a possible runtime or AOT compiler bug around the invocation of delegates on arm64 in concurrent settings (ie System.Threading.CancellationTokenSource.TimerCallback(Object ) getting some garbage argument due to a race condition in the code produced by the AOT compiler or in the implementation of delegates in the runtime).

But actually we've had issues with backgrounded iOS apps and the threadpool before (e.g. xamarin/xamarin-macios#7080)

Couple of questions:

  1. Are you using NSUrlSessionHandler or HttpClientHandler or something custom?
  2. When you say "We only use CancellationTokenSource (directly) when configuring an HttpClient" what exactly do you mean? You mean passing a cancellation token to httpClient.GetAsync() or something else?

@tipa
Copy link
Author

tipa commented Sep 27, 2023

As I noted earlier in this thread, I also see this crash reported for apps that do a lot of concurrent HTTP requests.
While these questions are to @divil5000, I'll try to add my input as well, as I'd really like to see this problem resolved.

  • Are you using NSUrlSessionHandler or HttpClientHandler or something custom?

I am using NSUrlSessionHandler (default constructor)

2. When you say "We only use CancellationTokenSource (directly) when configuring an HttpClient" what exactly do you mean? You mean passing a cancellation token to httpClient.GetAsync() or something else?

I am passing a cancellation token in some situations, but when the crashes happen (I sometimes experienced them myself), they seem to happen right when the http request is being sent out, before the token is cancelled or request timeouts would trigger. I am pretty sure the crashes just happen with a plain HttpClient.SendAsync(), without passing a cancellation token

@lambdageek
Copy link
Member

@tipa thanks!

Another question, do you have something enabled that is collecting Http telemetry? (https://learn.microsoft.com/en-us/dotnet/core/diagnostics/well-known-event-providers#systemnethttp-provider)

@tipa
Copy link
Author

tipa commented Sep 27, 2023

Not that I'm aware of, no.

@divil5000
Copy link

divil5000 commented Sep 28, 2023

To answer your questions @lambdageek,

  1. We use using the parameterless constructor for HttpClient so I believe that means NSUrlSessionHandler
  2. Yes, we pass a token to the HttpClient method. Here's the actual code we use to fire off most requests in our app:
var cts = new System.Threading.CancellationTokenSource();
cts.CancelAfter(Timeout); // Timeout is always 20 seconds
httpResponse = await httpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cts.Token).ConfigureAwait(false); // 2020/11/06 Added ConfigureAwait as it was necessary on Android, see https://github.com/xamarin/xamarin-android/issues/5264

I hope this is helpful for the repro.

@lambdageek
Copy link
Member

lambdageek commented Oct 2, 2023

Update can't get it to happen more than once. I looked at the disassembly for RunOrQueueCompletionAction to see if it's somehow passing a garbage argument that ProcessCompletedOuterTask can't cast properly, but the codegen looks correct.

I think I'm getting somewhere... Got this on an iPhone 15 (iOS 17.0) arm64 simulator on an M1 mac

Unhandled managed exception: Arg_InvalidCastException (System.InvalidCastException)
   at System.Threading.Tasks.UnwrapPromise`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ProcessCompletedOuterTask(Task )
   at System.Threading.Tasks.UnwrapPromise`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InvokeCore(Task )
   at System.Threading.Tasks.UnwrapPromise`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(Task )
   at System.Threading.Tasks.Task.RunOrQueueCompletionAction(ITaskCompletionAction , Boolean )
   at System.Threading.Tasks.Task.RunContinuations(Object )
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean )
   at System.Threading<…>

And a native stack like this:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: A8AE1E18-133D-42AD-B7ED-504454BF8138
CrashReporter Key:   1143D3D0-7711-BC35-8E10-8642D5EAA935
Hardware Model:      MacBookPro17,1
Process:             ios7-fafa [47137]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/ios7-fafa
Identifier:          com.companyname.ios7_fafa
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Role:                unknown
Parent Process:      launchd_sim [45796]
Coalition:           com.apple.CoreSimulator.SimDevice.CBD0CB33-4BE3-4B91-8565-C1897A58549C [4361]
Responsible Process: SimulatorTrampoline [8861]

Date/Time:           2023-10-02 13:27:31.0525 -0400
Launch Time:         2023-10-02 13:27:27.6811 -0400
OS Version:          macOS 13.6 (22G120)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: ios7-fafa [47137]

Triggered by Thread:  17

Thread 0:: tid_103 Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	       0x1054851d0 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x105496298 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x10548d3d8 mach_msg_overwrite + 540
3   libsystem_kernel.dylib        	       0x105485540 mach_msg + 20
4   CoreFoundation                	       0x1803c5ed8 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x1803c05b8 __CFRunLoopRun + 1148
6   CoreFoundation                	       0x1803bfd28 CFRunLoopRunSpecific + 572
7   GraphicsServices              	       0x18986ebc0 GSEventRunModal + 160
8   UIKitCore                     	       0x10df87fdc -[UIApplication _run] + 868
9   UIKitCore                     	       0x10df8bc54 UIApplicationMain + 124
10  libxamarin-dotnet.dylib       	       0x1054f1ff4 xamarin_UIApplicationMain + 24
11  ios7-fafa                     	       0x1040c1b30 wrapper_managed_to_native_UIKit_UIApplication_xamarin_UIApplicationMain_int_intptr_intptr_intptr_intptr_ + 176
12  ios7-fafa                     	       0x1041fd790 Microsoft_iOS_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 208 (UIApplication.cs:58)
13  libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
14  libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
15  libmonosgen-2.0.dylib         	       0x105af295c do_exec_main_checked + 104
16  libmonosgen-2.0.dylib         	       0x105c06a90 mono_jit_exec + 364
17  libxamarin-dotnet.dylib       	       0x105506608 xamarin_main + 972
18  ios7-fafa                     	       0x10451cf24 main + 64 (main.arm64.mm:93)
19  dyld_sim                      	       0x104e85558 start_sim + 20
20  dyld                          	       0x104d91f28 start + 2236

Thread 1:
0   libsystem_pthread.dylib       	       0x105606634 start_wqthread + 0

Thread 2:: SGen worker
0   libsystem_kernel.dylib        	       0x1054886d4 __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x10560b9e4 _pthread_cond_wait + 1220
2   libmonosgen-2.0.dylib         	       0x105b9c8f4 thread_func + 468
3   libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
4   libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 3:: Finalizer
0   libsystem_kernel.dylib        	       0x10548514c semaphore_wait_trap + 8
1   libmonosgen-2.0.dylib         	       0x105b28b84 finalizer_thread + 340
2   libmonosgen-2.0.dylib         	       0x105b0357c start_wrapper_internal + 324
3   libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
4   libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
5   libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 4::  Dispatch queue: com.apple.NSURLSession-work
0   libobjc.A.dylib               	       0x18005d600 DYLD-STUB$$pthread_setspecific + 4
1   libobjc.A.dylib               	       0x18005b2d8 objc_autoreleaseReturnValue + 208
2   CFNetwork                     	       0x1844482e0 0x184210000 + 2327264
3   CFNetwork                     	       0x1842bc3d4 0x184210000 + 705492
4   CFNetwork                     	       0x1844375f4 0x184210000 + 2258420
5   CFNetwork                     	       0x18421747c 0x184210000 + 29820
6   CFNetwork                     	       0x184231c80 0x184210000 + 138368
7   CFNetwork                     	       0x18443b488 0x184210000 + 2274440
8   libdispatch.dylib             	       0x1801424f4 _dispatch_call_block_and_release + 24
9   libdispatch.dylib             	       0x180143d3c _dispatch_client_callout + 16
10  libdispatch.dylib             	       0x18014be3c _dispatch_lane_serial_drain + 960
11  libdispatch.dylib             	       0x18014c9b4 _dispatch_lane_invoke + 388
12  libdispatch.dylib             	       0x180157d40 _dispatch_root_queue_drain_deferred_wlh + 276
13  libdispatch.dylib             	       0x18015738c _dispatch_workloop_worker_thread + 448
14  libsystem_pthread.dylib       	       0x105607878 _pthread_wqthread + 284
15  libsystem_pthread.dylib       	       0x10560663c start_wqthread + 8

Thread 5:
0   libsystem_pthread.dylib       	       0x105606634 start_wqthread + 0

Thread 6:: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib        	       0x1054851d0 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x105496298 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x10548d3d8 mach_msg_overwrite + 540
3   libsystem_kernel.dylib        	       0x105485540 mach_msg + 20
4   CoreFoundation                	       0x1803c5ed8 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x1803c05b8 __CFRunLoopRun + 1148
6   CoreFoundation                	       0x1803bfd28 CFRunLoopRunSpecific + 572
7   Foundation                    	       0x180dafa98 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8   Foundation                    	       0x180dafcbc -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9   UIKitCore                     	       0x10e02a304 -[UIEventFetcher threadMain] + 404
10  Foundation                    	       0x180dd627c __NSThread__start__ + 720
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 7:
0   libsystem_pthread.dylib       	       0x105606634 start_wqthread + 0

Thread 8:
0   libsystem_pthread.dylib       	       0x105606634 start_wqthread + 0

Thread 9:
0   libsystem_pthread.dylib       	       0x105606634 start_wqthread + 0

Thread 10:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 11:: .NET ThreadPool Gate
0   libsystem_kernel.dylib        	       0x1054886d4 __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x10560ba10 _pthread_cond_wait + 1264
2   libSystem.Native.dylib        	       0x104cc9220 SystemNative_LowLevelMonitor_TimedWait + 104
3   ios7-fafa                     	       0x104172308 wrapper_managed_to_native_Interop_Sys__LowLevelMonitor_TimedWaitg____PInvoke_67_0_intptr_int + 152 (/<unknown>:1)
4   ios7-fafa                     	       0x104388278 corlib_System_Threading_LowLevelMonitor_WaitCore_int + 52
5   ios7-fafa                     	       0x10439b79c corlib_System_Threading_WaitSubsystem_WaitableObject_Wait_Locked_System_Threading_WaitSubsystem_ThreadWaitInfo_int_bool_bool_System_Threading_WaitSubsystem_LockHolder_ + 204
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 12:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 13:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 14:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 15:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 16:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 17 Crashed:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x10548cfe8 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x10560b12c pthread_kill + 256
2   libsystem_c.dylib             	       0x1801375ec abort + 104
3   libmonosgen-2.0.dylib         	       0x105e1bd74 sigabrt_signal_handler.cold.1 + 48
4   libmonosgen-2.0.dylib         	       0x105c85094 sigabrt_signal_handler + 168
5   libsystem_platform.dylib      	       0x104d13c80 _sigtramp + 52
6   libsystem_pthread.dylib       	       0x10560b12c pthread_kill + 256
7   libsystem_c.dylib             	       0x1801375ec abort + 104
8   libxamarin-dotnet.dylib       	       0x1054fcefc xamarin_unhandled_exception_handler + 60
9   libmonosgen-2.0.dylib         	       0x105aa6ecc mono_invoke_unhandled_exception_hook + 132
10  libmonosgen-2.0.dylib         	       0x105b036b4 start_wrapper_internal + 636
11  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
12  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
13  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 18:: .NET ThreadPool Worker
0   libsystem_kernel.dylib        	       0x105485224 swtch_pri + 8
1   libsystem_pthread.dylib       	       0x1056085a8 cthread_yield + 28
2   libmonosgen-2.0.dylib         	       0x105b5c110 mono_threads_platform_yield + 12
3   libmonosgen-2.0.dylib         	       0x105ab4f0c ves_icall_System_Threading_Thread_YieldInternal + 12
4   ios7-fafa                     	       0x1040efef0 wrapper_managed_to_native_System_Threading_Thread_YieldInternal + 112 (/<unknown>:1)
5   ios7-fafa                     	       0x1043997c0 corlib_System_Threading_WaitSubsystem_UninterruptibleSleep0 + 40
6   ios7-fafa                     	       0x10437d810 corlib_System_Threading_Thread_StartCallback + 212
7   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
8   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
10  libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
11  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
12  libsystem_pthread.dylib       	       0x105606648 thread_start + 8

Thread 19:: .NET Timer
0   libsystem_kernel.dylib        	       0x1054886d4 __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x10560ba10 _pthread_cond_wait + 1264
2   libSystem.Native.dylib        	       0x104cc9220 SystemNative_LowLevelMonitor_TimedWait + 104
3   ios7-fafa                     	       0x104172308 wrapper_managed_to_native_Interop_Sys__LowLevelMonitor_TimedWaitg____PInvoke_67_0_intptr_int + 152 (/<unknown>:1)
4   ios7-fafa                     	       0x104388278 corlib_System_Threading_LowLevelMonitor_WaitCore_int + 52
5   ios7-fafa                     	       0x10439b79c corlib_System_Threading_WaitSubsystem_WaitableObject_Wait_Locked_System_Threading_WaitSubsystem_ThreadWaitInfo_int_bool_bool_System_Threading_WaitSubsystem_LockHolder_ + 204
6   libmonosgen-2.0.dylib         	       0x105bb3874 mono_jit_runtime_invoke + 1320
7   libmonosgen-2.0.dylib         	       0x105aeacbc mono_runtime_invoke_checked + 148
8   libmonosgen-2.0.dylib         	       0x105b03670 start_wrapper_internal + 568
9   libmonosgen-2.0.dylib         	       0x105b03408 start_wrapper + 44
10  libsystem_pthread.dylib       	       0x10560b428 _pthread_start + 116
11  libsystem_pthread.dylib       	       0x105606648 thread_start + 8


Thread 17 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0xffffffff98bf1d51   x5: 0x0000000000000008   x6: 0x000000016d256560   x7: 0x000000016d255c50
    x8: 0x000000016d257000   x9: 0xc7aeeee1835c9474  x10: 0x3d3d3d3d3d3d3d3d  x11: 0x3d3d3d3d3d3d3d3d
   x12: 0x3d3d3d3d3d3d3d3d  x13: 0x3d3d3d3d3d3d3d3d  x14: 0x3d3d3d3d3d3d3d3d  x15: 0x0a3d3d3d3d3d3d3d
   x16: 0x0000000000000148  x17: 0x000000018039c288  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x000000016d257000  x21: 0x0000000000007003  x22: 0x000000016d2570e0  x23: 0x000000016d257000
   x24: 0x0000000105f01440  x25: 0x0000000000000000  x26: 0x0000000000000000  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x000000016d256570   lr: 0x000000010560b12c
    sp: 0x000000016d256550   pc: 0x000000010548cfe8 cpsr: 0x40001000
   far: 0x000000010601f9ed  esr: 0x56000080  Address size fault

Binary Images:
       0x104d8c000 -        0x104e1bfff dyld (*) <49204446-242b-3d1e-9704-32f8ac99723e> /usr/lib/dyld
       0x107fe8000 -        0x107ff3fff libobjc-trampolines.dylib (*) <13823d40-f83a-3ddf-8c9c-4391bdc3d01f> /Volumes/VOLUME/*/libobjc-trampolines.dylib
       0x10530c000 -        0x1053c7fff libSystem.IO.Compression.Native.dylib (*) <53f336ac-6f97-3024-99be-290e2957e75f> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libSystem.IO.Compression.Native.dylib
       0x104cbc000 -        0x104ccbfff libSystem.Native.dylib (*) <d2743158-6edf-3ff8-b228-4ed1165d62d7> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libSystem.Native.dylib
       0x104ce0000 -        0x104ce3fff libSystem.Net.Security.Native.dylib (*) <a681ce55-793d-321d-ae59-b0a2de171c8e> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libSystem.Net.Security.Native.dylib
       0x104cf4000 -        0x104cfbfff libSystem.Security.Cryptography.Native.Apple.dylib (*) <82d688f6-3207-3151-82b4-c3e2c5b9e345> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libSystem.Security.Cryptography.Native.Apple.dylib
       0x1053dc000 -        0x105407fff libmono-component-debugger.dylib (*) <92545251-fdd2-3cbc-baaa-33bd9718d0e6> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libmono-component-debugger.dylib
       0x105424000 -        0x10545ffff libmono-component-diagnostics_tracing.dylib (*) <06e23b2d-2c01-3b1a-ac4f-034daddd5617> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libmono-component-diagnostics_tracing.dylib
       0x104d3c000 -        0x104d53fff libmono-component-hot_reload.dylib (*) <6b6e4314-b978-3d2d-ad69-21a34e027a04> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libmono-component-hot_reload.dylib
       0x105a7c000 -        0x105ec3fff libmonosgen-2.0.dylib (*) <cae2f3f8-1aa3-3b68-a9b9-d5c1c9bf4077> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libmonosgen-2.0.dylib
       0x1054f0000 -        0x10550bfff libxamarin-dotnet.dylib (*) <07ea76b5-0e70-3715-a2f2-8d69fa583859> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/libxamarin-dotnet.dylib
       0x10608c000 -        0x106157fff com.apple.quicklook (1.0) <989a71d9-2301-3180-898a-48e0e7ba746c> /Volumes/VOLUME/*/QuickLook.framework/QuickLook
       0x104cb0000 -        0x104cb3fff com.apple.UIKit (1.0) <27dd141d-93eb-389a-a9de-20322a90a2be> /Volumes/VOLUME/*/UIKit.framework/UIKit
       0x104d10000 -        0x104d17fff libsystem_platform.dylib (*) <9732e84b-ca21-3a30-9246-b6b230ce94fd> /usr/lib/system/libsystem_platform.dylib
       0x105484000 -        0x1054bbfff libsystem_kernel.dylib (*) <01eda75b-905a-3268-8a7e-d4914fb1837f> /usr/lib/system/libsystem_kernel.dylib
       0x105604000 -        0x105613fff libsystem_pthread.dylib (*) <27ce1820-cc5b-30ea-974a-1d844310c438> /usr/lib/system/libsystem_pthread.dylib
       0x10555c000 -        0x1055a3fff com.apple.DocumentManager (1.0) <aff49d72-caeb-34ee-a2e9-ab7687bbca03> /Volumes/VOLUME/*/DocumentManager.framework/DocumentManager
       0x10d3d0000 -        0x10ed0ffff com.apple.UIKitCore (1.0) <6b64a343-f832-3b1d-a6c3-f8ed32b35a83> /Volumes/VOLUME/*/UIKitCore.framework/UIKitCore
       0x105640000 -        0x105747fff com.apple.ShareSheet (1936.10.1.2.18) <00908d3a-bef2-3e76-b148-637416cf26d3> /Volumes/VOLUME/*/ShareSheet.framework/ShareSheet
       0x1058c0000 -        0x105947fff com.apple.PrintKitUI (1.0) <8bcb57a4-5419-3d3a-94cd-fe0749aadd3d> /Volumes/VOLUME/*/PrintKitUI.framework/PrintKitUI
       0x10693c000 -        0x106adffff com.apple.WebKitLegacy (8616) <ab615706-59b1-3450-8cf6-a9af3bf00f63> /Volumes/VOLUME/*/WebKitLegacy.framework/WebKitLegacy
       0x10a7c8000 -        0x10be27fff com.apple.JavaScriptCore (8616) <0b317b8d-2b5f-39e8-b04f-a3d1f4a7cf98> /Volumes/VOLUME/*/JavaScriptCore.framework/JavaScriptCore
       0x118d88000 -        0x11b6d3fff com.apple.WebCore (8616) <c796454a-0fac-3697-8b06-291cb7af0e44> /Volumes/VOLUME/*/WebCore.framework/WebCore
       0x106274000 -        0x10660ffff libANGLE-shared.dylib (*) <288dffed-ecee-39e9-b1c6-cc28ea58b453> /Volumes/VOLUME/*/WebCore.framework/Frameworks/libANGLE-shared.dylib
       0x106f50000 -        0x107027fff com.apple.WebGPU (8616) <d6fb20f0-c561-37cb-8fed-381418ee02b3> /Volumes/VOLUME/*/WebGPU.framework/WebGPU
       0x108d4c000 -        0x1097c3fff libwebrtc.dylib (*) <c7252466-0045-3c4b-a449-1eccf559cb7f> /Volumes/VOLUME/*/WebCore.framework/Frameworks/libwebrtc.dylib
       0x107604000 -        0x10773bfff com.apple.LinkPresentation (235) <e2ccb519-ed97-39ba-9011-b4657971d060> /Volumes/VOLUME/*/LinkPresentation.framework/LinkPresentation
       0x106834000 -        0x10686bfff com.apple.QuickLookUICore (1.0) <51c3aabf-4095-34a3-8177-313c75dc53a2> /Volumes/VOLUME/*/QuickLookUICore.framework/QuickLookUICore
       0x106cb4000 -        0x106dc3fff com.apple.VisionKitCore (1.0) <7fae4a41-7a07-31fb-9c93-368be6454ae2> /Volumes/VOLUME/*/VisionKitCore.framework/VisionKitCore
       0x109b14000 -        0x109ee3fff com.apple.MediaPlayer (1.0) <ed70641d-79d6-36fc-b222-7bf9c9ddcabe> /Volumes/VOLUME/*/MediaPlayer.framework/MediaPlayer
       0x107090000 -        0x107233fff com.apple.AVKit (1.0) <f095a516-4ea3-3249-b8c3-e7fb15da0686> /Volumes/VOLUME/*/AVKit.framework/AVKit
       0x113ea0000 -        0x114a1bfff com.apple.WebKit (8616) <9368a66c-7cee-329f-8248-062a32b2a5c4> /Volumes/VOLUME/*/WebKit.framework/WebKit
       0x110c20000 -        0x11267ffff com.apple.SwiftUI (5.0.83.1.105) <ff92863f-3762-39a2-bc7b-1fe45e10df0e> /Volumes/VOLUME/*/SwiftUI.framework/SwiftUI
       0x105a38000 -        0x105a53fff com.apple.mlcompiler.services (95) <bab278e9-61f1-388a-abf6-a24e9e5d58f4> /Volumes/VOLUME/*/MLCompilerServices.framework/MLCompilerServices
       0x10744c000 -        0x1074affff com.apple.Pegasus (1.0) <7134154b-f2d8-346f-b83a-37f0bfbe620d> /Volumes/VOLUME/*/Pegasus.framework/Pegasus
       0x1068c0000 -        0x1068d7fff com.apple.RecapPerformanceTesting (17) <74c6711c-e770-3875-81b6-a7aaca7bf050> /Volumes/VOLUME/*/RecapPerformanceTesting.framework/RecapPerformanceTesting
       0x107cb0000 -        0x107d9ffff com.apple.PDFKit (1.0) <a870268e-4071-3eaa-9f2d-e3c83ac8f99f> /Volumes/VOLUME/*/PDFKit.framework/PDFKit
       0x1078c4000 -        0x1078effff com.apple.VisionKit.VisionKitInternal (1.0) <e29bfd29-d858-33f5-84ea-aea08704a393> /Volumes/VOLUME/*/VisionKitInternal.framework/VisionKitInternal
       0x107534000 -        0x107573fff com.apple.CameraEditKit (1.0) <dbd62d2e-b2a6-3d83-be70-6a28ef613c83> /Volumes/VOLUME/*/CameraEditKit.framework/CameraEditKit
       0x104c98000 -        0x104c9bfff libswiftMetalKit.dylib (*) <e4dc9916-e67b-39b0-9e28-b3fd404a6cba> /Volumes/VOLUME/*/libswiftMetalKit.dylib
       0x1079b0000 -        0x1079cffff com.apple.MetalKit (159) <1bf3a693-50f4-3204-ba6d-38eeeba005ab> /Volumes/VOLUME/*/MetalKit.framework/MetalKit
       0x107920000 -        0x10794bfff com.apple.BaseBoardUI (651) <9bdec4ff-ff4e-39a6-9404-7c129dc37524> /Volumes/VOLUME/*/BaseBoardUI.framework/BaseBoardUI
       0x104e84000 -        0x104ecbfff dyld_sim (*) <993f9bdb-7b52-3b18-92a3-55f3471b53e5> /Volumes/VOLUME/*/dyld_sim
       0x1040b0000 -        0x104547fff com.companyname.ios7_fafa (1.0) <1d1e6f41-3341-3931-a951-bb55993f5a56> /Users/USER/Library/Developer/CoreSimulator/Devices/CBD0CB33-4BE3-4B91-8565-C1897A58549C/data/Containers/Bundle/Application/C5084E72-0E3E-4C41-9263-65AF76AF0D11/ios7-fafa.app/ios7-fafa
       0x180339000 -        0x1806ebfff com.apple.CoreFoundation (6.9) <c665e05f-5989-30d1-b748-7688b8590d39> /Volumes/VOLUME/*/CoreFoundation.framework/CoreFoundation
       0x18986b000 -        0x189873fff com.apple.GraphicsServices (1.0) <ba53ab8f-c1b1-315f-b8f0-95f69385bf2a> /Volumes/VOLUME/*/GraphicsServices.framework/GraphicsServices
       0x180030000 -        0x18006ceb8 libobjc.A.dylib (*) <227f6ac6-a518-3978-8801-b220a26f680d> /Volumes/VOLUME/*/libobjc.A.dylib
       0x184210000 -        0x18459efff com.apple.CFNetwork (1.0) <0c2537f1-3d7e-3125-8ac2-19079d5879dc> /Volumes/VOLUME/*/CFNetwork.framework/CFNetwork
       0x180140000 -        0x180185fff libdispatch.dylib (*) <5161220e-c794-3f5a-a4b4-52630f7c4665> /Volumes/VOLUME/*/libdispatch.dylib
       0x18076b000 -        0x18121ffff com.apple.Foundation (6.9) <508eec71-652e-35bc-b02c-7dff66ccd20a> /Volumes/VOLUME/*/Foundation.framework/Foundation
       0x1800c5000 -        0x18013ffff libsystem_c.dylib (*) <bfe8c5e8-6304-311e-86bb-69c45f0f96bb> /Volumes/VOLUME/*/libsystem_c.dylib

The app is a .NET 7 ios template app with this in the AppDelegate FinishedLaunching method:

		var f = typeof(HttpMessageInvoker).GetField("_handler", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
		var o = f?.GetValue(client);
		if (o?.GetType().FullName != "System.Net.Http.NSUrlSessionHandler") {
			SetText($"handler: {o?.GetType().FullName}");
		} else {
			Task.Run (() => {
				Thread.Sleep (3000);
				Task.Run(RunRedraw);
				for (int i = 0; i < NumTasks; i++) {
					StartFetch(i);
					//Thread.Sleep(10);
				}
			});
		}

where RunRedraw and StartFetch are like this:

	private static HttpClient client = new(new NSUrlSessionHandler());


	private void SetText(string text) {
		CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() => {
			label.Text = text;
			label.SetNeedsDisplay();
		});
	}

	enum State : byte {
		Unstarted,
		Started,
		Completed,
		Cancelled,
	}

	private const int NumTasks = 100;
	private byte[] states = new byte[NumTasks];

	private string faulting = string.Empty;


	private void UpdateState () {
		var text = $"{DateTime.Now:HH:mm:ss} ";
		for (int i = 0; i < NumTasks; i++) {
			text += (State)Volatile.Read (ref states[i]) switch {
				State.Unstarted => ".",
				State.Started => "S",
				State.Completed => "C",
				State.Cancelled => "X",
				_ => "?",
			};
			if (i == NumTasks / 2) {
				text += "\n";
			}
		}
		if (faulting != string.Empty) {
			text += $"\nFAULT: {faulting}";
		}
		SetText(text);
	}

	private async Task RunFetch(int i)
	{
		try {
		var cts = new CancellationTokenSource();
		cts.CancelAfter(TimeSpan.FromSeconds(20));
		try {
			Volatile.Write(ref states[i], (byte)State.Started);
			var message = new HttpRequestMessage(HttpMethod.Get, "https://www.example.com:81/");
			var response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cts.Token);
			Volatile.Write(ref states[i], (byte)State.Completed);
		} catch (TaskCanceledException) {
			Volatile.Write(ref states[i], (byte)State.Cancelled);
		}
		} catch (Exception e) {
			faulting = e.ToString();
		}
	}

	private void StartFetch(int i)
	{
		Task.Run(() => RunFetch(i));
	}

	private async Task RunRedraw()
	{
		while (true) {
			UpdateState();
			await Task.Delay(1000);
			var _ = Task.Run(() => {
				GC.Collect();
				GC.WaitForPendingFinalizers();
				GC.WaitForPendingFinalizers();
			});
		}
	}

To repro, launch the app and then hit "Home" in the first 3 seconds so the app is in the background before it launches the tasks.

There's some nonsense in my csproj file (I was trying, fruitlessly, to try to get it launched with AOT on the simulator) that I'm not sure is relevant. I'll try cleaning things up before uploading a repro project.

I wasn't getting anywhere with the app in the foreground. So folks guessing that it has to do with the app being in the background are very likely correct.

@divil5000
Copy link

I wonder if it's worth changing your repro so it waits for the entire HTTP response before continuing, and deliberately downloading a very large file, so the cancellation token actually fires while your app is backgrounded? This would simulate a poor internet connection situation.

@lambdageek
Copy link
Member

I wonder if it's worth changing your repro so it waits for the entire HTTP response before continuing, and deliberately downloading a very large file, so the cancellation token actually fires while your app is backgrounded? This would simulate a poor internet connection situation.

It actually is getting cancelled. a Get from https://example.com:81/ always hangs. I've also tried it with https://example.com/ - so the request succeeds. I can probably try doing half the requests to 81 and half to 443. It doesn't seem to matter.

It really doesn't feel like a problem with the http stack or with the threadpool. I think backgrounding the app just gives the threadpool a chance to lower the number of worker threads, and then the actual crash is some kind of a data race in the delegate implementation.

@divil5000
Copy link

Is there anything we can do, on the app side, to stop the entire app from crashing when this unhandled exception is thrown? At the moment we pick it up and record it for our own telemetry, but can't do much else. We are seeing over a hundred crashes on devices per day at the moment.

@lambdageek
Copy link
Member

lambdageek commented Oct 3, 2023

Update (one other thing I forgot to write down: I have no idea why this would only show up in net7 and not in classic Xamarin. This part of Mono doesn't change very often)

I managed to catch this in Xcode in the debugger (although mostly I was getting an seemingly spurious crash). As far as I can tell what is happening is we're getting garbage values in the MonoClass:supertypes field of some objects. (Probably due to two threads initializing that field at the same time).

For example in corlib_System_Threading_Tasks_UnwrapPromise_1_System_Threading_Tasks_VoidTaskResult_ProcessCompletedOuterTask_System_Threading_Tasks_Task we end up throwing from:

    0x102ee888c <+320>: adrp   x1, 0
    0x102ee8890 <+324>: add    x1, x1, #0x88c            ; <+320>
    0x102ee8894 <+328>: mov    w0, #0x9f
    0x102ee8898 <+332>: bl     0x102c3c014               ; p_2_plt_corlib__jit_icall_llvm_throw_corlib_exception_abs_trampoline_llvm

to reach 0x102ee888c we come from this code:

    0x102ee87e0 <+148>: ldr    x8, [x20]
    0x102ee87e4 <+152>: adrp   x9, 291
    0x102ee87e8 <+156>: ldr    x8, [x8]
    0x102ee87ec <+160>: str    x8, [x0, #0x50]
    0x102ee87f0 <+164>: ldr    x8, [x9, #0x298]
    0x102ee87f4 <+168>: str    x8, [x0, #0x58]
    0x102ee87f8 <+172>: ldr    x8, [x20]
    0x102ee87fc <+176>: ldr    x9, [x9, #0x298]
    0x102ee8800 <+180>: ldr    x8, [x8]
    0x102ee8804 <+184>: ldr    x8, [x8, #0x10]
    0x102ee8808 <+188>: ldr    x8, [x8, #0x10]
    0x102ee880c <+192>: cmp    x8, x9
    0x102ee8810 <+196>: b.ne   0x102ee888c               ; <+320>

which I think is this code

case TaskStatus.RanToCompletion:
ProcessInnerTask(task is Task<Task<TResult>> taskOfTaskOfTResult ? // it's either a Task<Task> or Task<Task<TResult>>
taskOfTaskOfTResult.Result : ((Task<Task>)task).Result);

and specifically the cast ((Task<Task>)task)

that sequence of assembly code looks like it is emitted by

MONO_EMIT_NEW_LOAD_MEMBASE (cfg, stypes_reg, klass_reg, GINTPTR_TO_TMREG (m_class_offsetof_supertypes ()));
MONO_EMIT_NEW_LOAD_MEMBASE (cfg, stype, stypes_reg, ((m_class_get_idepth (klass) - 1) * TARGET_SIZEOF_VOID_P));
mini_emit_class_check_inst (cfg, stype, klass, klass_inst);

(the offset of supertypes is indeed 0x10, and Task`1<Task> has idepth == 3, so that's 0x102ee87c8 <+124>: ldr x8, [x8, #0x10])

Annoyingly the debugger doesn't actually show me that the object in x20 has it's supertypes set incorrectly. I guess by the time we hit my breakpoint (in the beginning of throwing the InvalidCastException) it's already been properly initialized by whatever other thread is trying to write to it.


@divil5000 I think eventually you might try adding some code at app startup that does some gratuitous type casts of some CancelationTokenSource and DelayPromise values to their own types (or to a parent type). Something like:

[MethodImpl(MethodImplOptions.NoInlining)]
static CancellationTokenSource CastToCTS(object o)
{
   return (CancellationTokenSource)o;
}

...
var cts = new CancellationTokenSource();
CastToCTS(cts).Dispose();

(and same with DelayPromise --- although you'll need to use private reflection to instantiate that one since it's an internal type in System.Threading.Tasks.Task)

I'm not sure this will help (for one, I'm not sure this will get compiled the same way by the AOT compiler - I still need to verify that), but so far this is the only suggestion I have...

@lambdageek
Copy link
Member

Hmm... actually I think I'm wrong. In this code:

    0x102ee87e4 <+152>: adrp   x9, 291
    0x102ee87e8 <+156>: ldr    x8, [x8]
    0x102ee87ec <+160>: str    x8, [x0, #0x50]
    0x102ee87f0 <+164>: ldr    x8, [x9, #0x298]
    0x102ee87f4 <+168>: str    x8, [x0, #0x58]
    0x102ee87f8 <+172>: ldr    x8, [x20]
    0x102ee87fc <+176>: ldr    x9, [x9, #0x298]
    0x102ee8800 <+180>: ldr    x8, [x8]
    0x102ee8804 <+184>: ldr    x8, [x8, #0x10]
    0x102ee8808 <+188>: ldr    x8, [x8, #0x10]
    0x102ee880c <+192>: cmp    x8, x9
    0x102ee8810 <+196>: b.ne   0x102ee888c               ; <+320>

it actually looks like x9 is zero. So it's not the object that has the problem. it's that MONO_RGCTX_INFO_KLASS is somehow null.

The workaround i proposed won't work

@lambdageek
Copy link
Member

@lateralusX I think this is the same as #75088 - see my previous two comments - this is some LLVM AOT code that is seeing a NULL value in a GOT aotconst. I think the fences and memory barriers in your PR would resolve this issue, too. What do you think? Also, what do you think about the risk of backporting to net7?

@lateralusX
Copy link
Member

lateralusX commented Oct 4, 2023

Yes, if you have got passed method_init and still sees NULL values in used GOT slots for that method, that probably means you hit the race where that thread exited its call to method_init before the stores into needed GOT slot has happened or became visible by the other thread. This is an LLVM only issue, meaning that it won't reproduce when running without LLVM. When I originally investigate that issue it caused rare random crashes that could occur at any point during apps lifetime, because a method calls its method_init only on first call to to the method, and it needs to race with another thread doing the same thing to expose the potential race.

This fix has been implemented and used in a downstream repo running in some large apps, installed and executed in very large quantities for over a year, and it eliminated the in-frequent crashes previously seen by those apps and didn't cause any regression (x64). It has been in dotnet/runtime main for over a year, so since the fix have been around for sometime and it has been applied to both mono/mono and dotnet/runtime repro's. I believe it should be a small risk of backporting it to net7, especially since we see issues potentially affected by it and its LLVM only.

@divil5000
Copy link

We have never seen this issue in the past, when running on the Xamarin framework. Only since our latest release where we changed to net7-ios. In both cases we are using LLVM. Is that expected? It seems to contradict what @lateralusX is saying.

@michaldobrodenka
Copy link

We have never seen this issue in the past, when running on the Xamarin framework. Only since our latest release where we changed to net7-ios. In both cases we are using LLVM. Is that expected? It seems to contradict what @lateralusX is saying.

I haven't seen 1 crash of this type after we turned off LLVM. We had crash like this about every day.

@lateralusX
Copy link
Member

lateralusX commented Oct 4, 2023

We have never seen this issue in the past, when running on the Xamarin framework. Only since our latest release where we changed to net7-ios. In both cases we are using LLVM. Is that expected? It seems to contradict what @lateralusX is saying.

Xamarin runs on a Mono branch 2020-2 and the critical changes around this race was introduced later in both mono/mono as well as dotnet/runtime, so running on a later mono/mono branch as well as dotnet/runtime branch will hit it, but not the branch used by legacy Xamarin. That might explain what you have been identifying. On the product I originally hit and analyzed the issue we didn't see it until after upgrading to a later mono/mono commit, not included in Mono's 2020-2 branch.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 4, 2023
@lambdageek lambdageek modified the milestones: 8.0.0, 7.0.x Oct 4, 2023
@lambdageek
Copy link
Member

Thanks for the detailed explanation (and I missed that we changed this code relatively recently - that explains why Xamarin wasn't affected).

I'm going to try a local build of #93006 to verify that it makes the crash go away (It's quite infrequent for me under Xcode so if I don't see if after a couple hundred launches, I'm going to consider it resolved).

lambdageek added a commit that referenced this issue Oct 6, 2023
Backport of #75088 to release/7.0-staging

Fixes #81211 

## Customer Impact

Customers targeting Apple platforms using LLVM AOT codegen (the default) in highly concurrent settings (such as firing off multiple simultaneous async HTTP requests) may experience unexpected behavior such as InvalidCastExceptions, NullReferenceExceptions or crashes.

## Testing

Manual testing

## Risk

Low.  This code has been running on .NET 8 `main` for over a year in CI, as well as on some other non-mobile platforms

---

* [Mono] Race in init_method when using LLVM AOT.

When using LLVM AOT codegen, init_method updates two GOT slots.
These slots are initialized as part of init_method,
but there is a race between initialization of the two slots. Current
implementation can have two threads running init_method for the same
method, but as soon as:

[got_slots [pindex]] = addr

store is visible, it will trigger other threads to return back from
init_method, but since that could happen before the corresponding
LLVM AOT const slot is set, second thread will return to method
calling init_method, load the LLVM aot const, and crash when
trying to use it (since its still NULL).

This crash is very rare but have been identified on x86/x64 CPU's,
when one thread is either preempted between updating regular GOT slot
and LLVM GOT slot or store into LLVM GOT slot gets delayed in
store buffer. I have also been able to emulate the scenario in debugger,
triggering the issue and crashing in the method loading from LLVM aot
const slot.

Fix change order of updates and make sure the update of LLVM aot const
slot happens before memory_barrier, since:

got [got_slots [pindex]] = addr;

have release semantics in relation to addr and update of LLVM aot const
slot. Fix also add acquire/release semantics for ji->type in init_method
since it is used to guard if a thread ignores a patch or not and it
should not be re-ordered with previous stores, since it can cause
similar race conditions with updated slots.

* Move register_jump_target_got_slot above mono_memory_barrier.

* revert unintentional branding change

---------

Co-authored-by: vseanreesermsft <78103370+vseanreesermsft@users.noreply.github.com>
Co-authored-by: lateralusX <lateralusx.github@gmail.com>
Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 6, 2023
@divil5000
Copy link

So where are we with this issue? Will we have to move to net8-ios to fix it (when it's released) or will there be a patch to net7-ios at some point?

@lambdageek
Copy link
Member

It's fixed in .NET 8 RC2, and there is a backport that will be in an upcoming .NET 7 servicing release

@tipa
Copy link
Author

tipa commented Nov 4, 2023

@lambdageek thanks a lot for the fix - the crashes I reported in my first post of this thread have gone away!
However I still see those Exceptions (both the ArrayTypeMismatchException & NullReferenceExceptions) that I reported in this comment. Should I file a separate bug report for them? They also started to happen after migrating from Xamarin.iOS to .NET7

@lewing lewing closed this as completed Feb 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests