[Gc] Allowing SIGINT during garbage collection may result in deadlock

Burkhard Linke blinke at cebitec.uni-bielefeld.de
Mon Apr 19 07:42:08 PDT 2010


Hi,

I've stumpled across a deadlock during execution of a mono application using a 
recent cvs checkout of bdwgc under Solaris 10/x86.

All threads except the garbage collecting one are either suspended during 
stopping the world or correctly blocked by other means (IO, sleep for non GC 
threads etc).

The garbage collecting thread was interrupted by SIGINT, which is unblocked in 
GC_remove_allowed_signals(). The deadlock occurs during the fact that the 
mono signal handlers is invoked and attempts to allocate memory. Excerpt of 
the stacktrace of garbage collecting thread:

 fffffd7ffef072f7 lwp_park (0, 0, 0)
 fffffd7ffeeffd08 mutex_lock_impl () + e8
 fffffd7ffeeffdfb mutex_lock () + b
 fffffd7fff28506c GC_lock () + 38
 fffffd7fff27298b GC_core_gcj_malloc () + 113
 fffffd7fff283785 GC_gcj_malloc () + 225
 00000000005900bf mono_object_new_alloc_specific () + 2f
 0000000000590878 mono_object_new_specific () + 88
 0000000000595427 mono_method_call_message_new () + 47
 00000000005ffadf sigint_handler () + df
 fffffd7ffef07386 __sighndlr () + 6
 fffffd7ffeefbc32 call_user_handler () + 252
 fffffd7ffeefbe4e sigacthandler (2, 0, fffffd7ff75ff3e0) + de
 --- called from signal handler with signal 2 (SIGINT) ---
 fffffd7fff2782b4 GC_push_next_marked_uncollectable () + 24
 fffffd7fff2765e1 GC_mark_some () + 1b5
 fffffd7fff26bab4 GC_stopped_mark () + a4
 fffffd7fff26b7c4 GC_try_to_collect_inner () + 138
 fffffd7fff26c93f GC_collect_or_expand () + c7
 fffffd7fff26cbc9 GC_allocobj () + f9
 fffffd7fff274492 GC_generic_malloc_inner () + 17e
 fffffd7fff275707 GC_generic_malloc_many () + 277
 fffffd7fff2837ea GC_gcj_malloc () + 28a
 fffffd7ffe8129af ???????? ()
 ....

Since the lock is already held by the very same thread GC_lock() blocks and 
results in a dead lock. The same problem may occur in any application that is 
allocating memory during the SIGINT handler (or one of the other unblocked 
signals' handler).

I would propose blocking the signals during garbage collection, since allowing 
them may result in undefined behaviour. Any comments on this?

Regards,
Burkhard Linke



More information about the Gc mailing list