Bug 15759 - Mono GC deadlock
Summary: Mono GC deadlock
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
Depends on:
Reported: 2013-10-28 19:44 UTC by Sergey Zhukov
Modified: 2015-06-01 18:12 UTC (History)
4 users (show)

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 GitHub or Developer Community 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:

Description Sergey Zhukov 2013-10-28 19:44:35 UTC
When I try to run the latest version of monodevelop it usually hangs when trying to open my solutions. I look into gdb and found that deadlock is occured in GC. The backtrace of deadlocking threads is below. 
You can see, that 
thread 1 
locks GC_LOCK at step #11 (mono_gc_alloc_vector)
tries to lock domain->lock at step #4 (jit_info_table_free)
thread 2
locks domain->lock at step #5 (mono_type_get_object)
tries to lock GC_LOCK at step #4 (mono_gc_allock_pinned_obj)  

and this produces deadlock

Mono Runtime Engine version 3.2.5 (master/6a9c585 Fri Oct 25 01:56:00 NOVT 2013)

Thread 1
#0  0x40022424 in __kernel_vsyscall ()
#1  0x4008a5a2 in __lll_lock_wait () from /lib/i386-linux-gnu/libpthread.so.0
#2  0x40085ebb in _L_lock_764 () from /lib/i386-linux-gnu/libpthread.so.0
#3  0x40085d75 in pthread_mutex_lock ()
   from /lib/i386-linux-gnu/libpthread.so.0
#4  0x081e776f in jit_info_table_free (table=0x4cc573e8) at domain.c:216
#5  0x082780ab in try_free_delayed_free_item (lock_free_context=0)
    at hazard-pointer.c:213
#6  0x08278787 in mono_thread_hazardous_try_free_some ()
    at hazard-pointer.c:259
#7  0x082420ad in sgen_restart_world (generation=0, timing=0x446ff598)
    at sgen-stw.c:280
#8  0x0821fa7c in sgen_perform_collection (requested_size=4096, 
    generation_to_collect=0, reason=0x83488c5 "Nursery full", 
    wait_to_finish=<optimized out>) at sgen-gc.c:3525
#9  0x0821ffd4 in sgen_ensure_free_space (size=4096) at sgen-gc.c:3414
#10 0x082356d6 in mono_gc_alloc_obj_nolock (vtable=
    vtable("System.Collections.Generic.Link[]"), size=<optimized out>)
    at sgen-alloc.c:288
#11 0x08235a04 in mono_gc_alloc_vector (vtable=
    vtable("System.Collections.Generic.Link[]"), size=912, max_length=112)
    at sgen-alloc.c:491
#12 0x4048c023 in ?? ()
---Type <return> to continue, or q <return> to quit---
#13 0x4048a514 in ?? ()
#14 0x416c4bcd in System.Collections.Generic.Dictionary`2:InitArrays (this=
    ..., size=1084332864) at <unknown>:278
#15 0x416c4b30 in System.Collections.Generic.Dictionary`2:Init (this=..., 
    capacity=112, hcp=...) at <unknown>:272
#16 0x416c4965 in System.Collections.Generic.Dictionary`2:.ctor (this=..., 
    capacity=100, comparer=...) at <unknown>:252
#17 0x4fa2be10 in ?? ()
#18 0x4fbd32cc in ?? ()
#19 0x4fbd2ed4 in ?? ()
#20 0x4fa2baf0 in ?? ()

Thread 2
#0  0x40022424 in __kernel_vsyscall ()
#1  0x4008a5a2 in __lll_lock_wait () from /lib/i386-linux-gnu/libpthread.so.0
#2  0x40085ead in _L_lock_686 () from /lib/i386-linux-gnu/libpthread.so.0
#3  0x40085cf3 in pthread_mutex_lock ()
   from /lib/i386-linux-gnu/libpthread.so.0
#4  0x08235b89 in mono_gc_alloc_pinned_obj (vtable=vtable("System.MonoType"), 
    size=16) at sgen-alloc.c:585
#5  0x08207469 in mono_type_get_object (domain=0x9f63648, type=0xa7add5c
{genericinst, "Enumerator", [{class, "MonoDevelop.Ide.TypeSystem.FoldingRegion"}], []>}) at reflection.c:6527
#6  0x081f3afe in mono_class_create_runtime_vtable (raise_on_error=0, class=
"Enumerator<{class, "MonoDevelop.Ide.TypeSystem.FoldingRegion"}>", domain=
    0x9f63648) at object.c:2108
#7  mono_class_vtable_full (domain=0x9f63648, class=0xa7add5c
"Enumerator<{class, "MonoDevelop.Ide.TypeSystem.FoldingRegion"}>", 
    raise_on_error=0) at object.c:1815
#8  0x081f40cf in mono_class_vtable (domain=0x9f63648, class=0xa7add5c
"Enumerator<{class, "MonoDevelop.Ide.TypeSystem.FoldingRegion"}>")
    at object.c:1786
#9  0x080a8e69 in mono_method_to_ir (cfg=0x5242e450, method=
    "System.Collections.Generic.List`1:GetEnumerator ()", start_bblock=
    0x52308bcc, end_bblock=0x52308c7c, return_var=0x52308b9c, dont_inline=
---Type <return> to continue, or q <return> to quit---
    0x523331f8, inline_args=0x52336d90, inline_offset=381, is_virtual_call=1)
    at method-to-ir.c:9147
#10 0x080b0d87 in inline_method (cfg=0x5242e450, cmethod=<optimized out>, sp=
    0x52336d90, ip=0x4541a9b1 "o\\\006", real_offset=381, dont_inline=
    0x52365db0, inline_always=0, fsig=<optimized out>) at method-to-ir.c:5705
#11 0x080a0fc5 in mono_method_to_ir (cfg=0x5242e450, method=
    "<GenerateFoldings>c__Iterator0:MoveNext ()", start_bblock=0x5232514c, 
    end_bblock=0x523251fc, return_var=0x0, dont_inline=0x52365db0, inline_args=
    0x0, inline_offset=0, is_virtual_call=0) at method-to-ir.c:7994
#12 0x08067889 in mini_method_compile (method=
    "<GenerateFoldings>c__Iterator0:MoveNext ()", opts=110193151, domain=
    0x9f63648, run_cctors=1, compile_aot=0, parts=0) at mini.c:5132
#13 0x080694bb in mono_jit_compile_method_inner (jit_ex=0x4dbbcd6c, opt=
    110193151, target_domain=0x9f63648, method=
    "<GenerateFoldings>c__Iterator0:MoveNext ()") at mini.c:5877
#14 mono_jit_compile_method_with_opt (method=
    "<GenerateFoldings>c__Iterator0:MoveNext ()", opt=110193151, ex=0x4dbbcd6c)
    at mini.c:6148
#15 0x0806a0be in mono_jit_compile_method (method=
    "<GenerateFoldings>c__Iterator0:MoveNext ()") at mini.c:6186
#16 0x080ff16a in common_call_trampoline (regs=0x4dbbce38, code=
    0x416ca3d7 "\203\304\020\205\300u\252\203\354\f\350\005", m=
    "<GenerateFoldings>c__Iterator0:MoveNext ()", vt=
---Type <return> to continue, or q <return> to quit---
    vtable("<GenerateFoldings>c__Iterator0"), vtable_slot=<optimized out>, 
    need_rgctx_tramp=0, tramp=<optimized out>) at mini-trampolines.c:577
#17 0x40478c3c in ?? ()
#18 0x416ca488 in System.Collections.Generic.List`1:AddRange (this=..., 
    collection=...) at <unknown>:160
#19 0x50386870 in ?? ()
#20 0x4fa0d090 in ?? ()
#21 0x4fa0b86d in ?? ()
#22 0x4fa0b764 in ?? ()
#23 0x4fa0b4ac in ?? ()
#24 0x40489d75 in ?? ()
#25 0x0806a1cd in mono_jit_runtime_invoke (method=
    "System.Threading.WaitCallback:Invoke ()", obj=0x50326230, params=
    0x4dbbd25c, exc=0x4dbbd254) at mini.c:6590
#26 0x081f4fff in mono_runtime_invoke (method=
    "System.Threading.WaitCallback:Invoke ()", obj=0x50326230, params=
    0x4dbbd25c, exc=0x4dbbd254) at object.c:2827
#27 0x081f5e75 in mono_runtime_delegate_invoke (delegate=0x50326230, params=
    0x4dbbd25c, exc=0x4dbbd254) at object.c:3538
#28 0x081d5655 in mono_async_invoke (ares=0x502cd8d0, tp=<optimized out>)
    at threadpool.c:621
#29 async_invoke_thread (data=0x502cd8d0) at threadpool.c:1517
#30 0x081cfc39 in start_wrapper_internal (data=0x44506730) at threads.c:609
---Type <return> to continue, or q <return> to quit---
#31 start_wrapper (data=0x44506730) at threads.c:654
#32 0x08269fe2 in thread_start_routine (args=0x9f5b5ec) at wthreads.c:294
#33 0x0827aade in inner_start_thread (arg=0x44505478)
    at mono-threads-posix.c:49
#34 0x40083d4c in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#35 0x40186dde in clone () from /lib/i386-linux-gnu/libc.so.6
Comment 1 Rodrigo Kumpera 2013-10-29 08:48:15 UTC
Working on it.
Comment 2 Rodrigo Kumpera 2013-12-06 15:28:31 UTC
Fixed in master.
Comment 3 Sergey Zhukov 2013-12-13 15:38:41 UTC
During last week I did not get any deadlocks while using monodevelop with this patch. Seems to be working.