Bug 59994 - Deadlock in the runtime when the GC runs and the XI runtime is releasing managed refs
Summary: Deadlock in the runtime when the GC runs and the XI runtime is releasing mana...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-10-05 17:30 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2017-10-09 09:06 UTC (History)
1 user (show)

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


Attachments
bt.crash (158.56 KB, text/plain)
2017-10-05 17:30 UTC, Rolf Bjarne Kvinge [MSFT]
Details

Description Rolf Bjarne Kvinge [MSFT] 2017-10-05 17:30:01 UTC
Created attachment 25127 [details]
bt.crash

See attached crash report

Thread 12 has the framework lock, and is waiting for something (I'm not sure what if it has something to do with the GC or if it's managed code trying to lock an object)

> 0   libsystem_kernel.dylib        	0x083a695a semaphore_wait_trap + 10
> 1   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x00270a4d mono_monitor_try_enter_inflated + 861 (mono-os-semaphore.h:90)
> 2   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0026fdbb mono_monitor_try_enter_internal + 107 (monitor.c:1016)
> 3   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002701df mono_monitor_enter_v4_internal + 79 (monitor.c:1158)
> 4   ???                           	0x21f438d0 0 + 569653456
> 5   ???                           	0x21f43774 0 + 569653108
> 6   ???                           	0x21f436ec 0 + 569652972
> 7   ???                           	0x21f435c0 0 + 569652672
> 8   ???                           	0x206246d8 0 + 543311576
> 9   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x003598fb xamarin_unregister_nsobject + 59 (.delegates.inc:207)
> 10  com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0035c47c xamarin_release_managed_ref + 236

Thread 0 is trying to stop the world, but is waiting for the framework lock:

> 0   libsystem_kernel.dylib        	0x083ae346 __psynch_mutexwait + 10
> 1   libsystem_pthread.dylib       	0x083dd4f1 _pthread_mutex_lock_wait + 86
> 2   libsystem_pthread.dylib       	0x083dac92 _pthread_mutex_lock_slow + 302
> 3   libsystem_pthread.dylib       	0x083dab45 pthread_mutex_lock + 127
> 4   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0035eb60 gc_event_callback(_MonoProfiler*, MonoGCEvent, int) + 96 (runtime.m:859)
> 5   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0028aa98 gc_event_cb + 24 (profiler.c:679)
> 6   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0028a304 mono_profiler_raise_gc_event + 68 (profiler-events.h:68)
> 7   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0029ee75 sgen_client_stop_world + 1381 (sgen-stw.c:109)
> 8   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fcc87 sgen_stop_world + 71 (sgen-gc.c:3801)
> 9   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fc769 sgen_perform_collection_inner + 121 (sgen-gc.c:2520)
> 10  com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fc6bb sgen_ensure_free_space + 155 (sgen-gc.c:2500)
> 11  com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002f2e28 sgen_alloc_obj_nolock + 824 (sgen-alloc.c:256)
> 12  com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002f3347 sgen_alloc_obj + 103 (sgen-alloc.c:423)
> 13  com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x00295d60 mono_gc_alloc_obj + 32 (sgen-mono.c:948)

Threads 3, 5 and 10 are trying to run the GC:

> Thread 3:: tid_260b
> 3   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fdf38 sgen_gc_lock + 72 (mono-os-mutex.h:99)
> 4   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fe723 sgen_gc_collect + 19 (sgen-gc.c:3088)
> 5   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0035c642 pump_gc(void*) + 66

> Thread 5:: tid_8407
> 3   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fdf38 sgen_gc_lock + 72 (mono-os-mutex.h:99)
> 4   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002f34b5 sgen_alloc_obj_mature + 37 (sgen-alloc.c:76)
> 5   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x00295e00 mono_gc_alloc_mature + 32 (sgen-mono.c:970)
> 6   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x00284170 mono_object_new_mature + 64 (object.c:5497)
> 7   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002bd726 create_internal_thread_object + 54 (threads.c:553)
> 8   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002bd663 mono_thread_create_internal + 35 (threads.c:1211)

> Thread 10:: Timer-Scheduler
> 3   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002fdf38 sgen_gc_lock + 72 (mono-os-mutex.h:99)
> 4   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x002f333d sgen_alloc_obj + 93 (sgen-alloc.c:423)
> 5   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x00295d60 mono_gc_alloc_obj + 32 (sgen-mono.c:948)
> 6   ???                           	0x20623dd9 0 + 543309273

Threads 6, 7, 8, 9, 11, 13, 14, 16, 17, 18, 20 are all trying to get the framework lock:

> 4   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0035a2d3 xamarin_framework_peer_lock + 51 (runtime.m:348)
> 5   com.xamarin.mscorlibtests-watch.watchkitapp.watchkitextension	0x0035c463 xamarin_release_managed_ref + 211 (runtime.m:1891)
> 6   ???                           	0x21f43118 0 + 569651480

In other words: there seems to be a race deadlock between the GC lock and the framework lock.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2017-10-05 17:39:00 UTC
master: https://github.com/xamarin/xamarin-macios/pull/2848

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