Bug 39941 - Deadlock in GC.Collect (sgen & boehm)
Summary: Deadlock in GC.Collect (sgen & boehm)
Status: RESOLVED NORESPONSE
Alias: None
Product: Runtime
Classification: Mono
Component: GC (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Kratzer Kevin
URL:
Depends on:
Blocks:
 
Reported: 2016-03-28 08:23 UTC by Kratzer Kevin
Modified: 2017-10-11 17:22 UTC (History)
4 users (show)

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


Attachments

Description Kratzer Kevin 2016-03-28 08:23:20 UTC
I'm experiencing an deadlock when calling the GC in the following way: managed -> managed-to-native -> native-to-managed -> GC.Collect()
The deadlock also occurs when GC.Collect() is not called directly but triggered by the runtime at an arbitrary time.

The same code works fine on Windows (mono & visual studio) but results in a deadlock on Linux using --gc=sgen or --gc=boehm.

Xubuntu 15.10
mono 4.2.3.4.

> (gdb) where
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00000000005f9d1c in ?? ()
#2  0x00000000005ece89 in ?? ()
#3  0x00000000005f3717 in ?? ()
#4  0x00000000005e63f2 in ?? ()
#5  0x00000000005e6665 in ?? ()
#6  0x00000000005e8d1e in ?? ()
#7  0x00000000005e8f88 in ?? ()
#8  0x00000000415844d2 in ?? ()
#9  0x0000000000000000 in ?? ()


> (gdb) mono_backtrace 15
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
185	in ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
#1  0x00000000005f9d1c in ?? ()
#2  0x00000000005ece89 in ?? ()
#3  0x00000000005f3717 in ?? ()
#4  0x00000000005e63f2 in ?? ()
#5  0x00000000005e6665 in ?? ()
#6  0x00000000005e8d1e in ?? ()
#7  0x00000000005e8f88 in ?? ()
#8 0x415844d2 in  (wrapper managed-to-native) System.GC:InternalCollect (int) + 0x52 (0x41584480 0x415844fe) [0xbc3080 - Demo.Minimal.exe]
#9  0x0000000000000000 in ?? ()
Initial frame selected; you cannot go up.


> (gdb) mono_stack
"<unnamed thread>" tid=0x0x7f61c7764780 this=0x0x7f61c76bc130 thread handle 0x403 state : not waiting owns ()
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.GC.InternalCollect (int) <0xffffffff>
  at System.GC.Collect () <0x00010>
  at Demo.Minimal.Browser.DemoRenderProcessHandler.OnContextCreated (CefBrowser,CefFrame,CefV8Context) <0x00172>
  at CefRenderProcessHandler.on_context_created (Interop.cef_render_process_handler_t*,Interop.cef_browser_t*,Interop.cef_frame_t*,Interop.cef_v8context_t*) <0x0005a>
  at (wrapper native-to-managed) CefRenderProcessHandler.on_context_created (Interop.cef_render_process_handler_t*,Interop.cef_browser_t*,Interop.cef_frame_t*,Interop.cef_v8context_t*) <0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Interop.libcef.execute_process (Interop.cef_main_args_t*,Interop.cef_app_t*,void*) <0xffffffff>
  at CefRuntime.ExecuteProcess (CefMainArgs,CefApp,intptr) <0x0006f>
  at Demo.Minimal.MinimalDemoApp.Run (string[]) <0x001d3>
  at Demo.Minimal.Program.Main (string[]) <0x0026b>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>



---------------------
> mono --version

Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

> apt-cache policy mono-complete 

mono-complete:
  Installed: 4.2.3.4-0xamarin2
  Candidate: 4.2.3.4-0xamarin2
  Version table:
 *** 4.2.3.4-0xamarin2 0
        500 http://download.mono-project.com/repo/debian/ wheezy/main amd64 Packages
        100 /var/lib/dpkg/status
     3.2.8+dfsg-4ubuntu4 0
        500 http://jp.archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages

> cat /proc/version
Linux version 4.2.0-34-generic (buildd@lgw01-54) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) ) #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016
Comment 1 Kratzer Kevin 2016-03-28 08:34:41 UTC
same for alpha build of mono sgen & boehm
> mono --version
Mono JIT compiler version 4.4.0 (Stable 4.4.0.40/f8474c4 Wed Mar 16 17:01:03 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

> apt-cache policy mono-complete
mono-complete:
  Installed: 4.4.0.40-0xamarin1
  Candidate: 4.4.0.40-0xamarin1
  Version table:
 *** 4.4.0.40-0xamarin1 0
        500 http://download.mono-project.com/repo/debian/ alpha/main amd64 Packages
        100 /var/lib/dpkg/status
     4.2.3.4-0xamarin2 0
        500 http://download.mono-project.com/repo/debian/ wheezy/main amd64 Packages
     3.2.8+dfsg-4ubuntu4 0
        500 http://jp.archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages
Comment 2 Kratzer Kevin 2016-03-29 01:10:24 UTC
Running mono(4.2.3.4/832de4b) with
export MONO_GC_DEBUG=9,check-at-minor-collections,check-scan-starts
The following log will be produced before the deadlock occurs:

Start major collection 0
Scanning pinned roots (13538 bytes, 104/9 entries)
Finding pinned pointers: 120 in 980 usecs
old generation done
Finalize queue handling scan for old generation: 507 usecs 2 ephemeron rounds
Comment 3 Alexander Köplinger [MSFT] 2016-04-05 01:04:37 UTC
Please provide a sample app or code that shows the problem. Thank you!
Comment 4 Rodrigo Kumpera 2017-10-11 17:22:12 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!

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