-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Avalonia causes a deadlock in mono's runtime during Garbagge Collection in macOS #9444
Comments
Yes, #9376 fixes exactly that scenario. I don't see |
I am trying to test against 11.0.0-preview4, after migrating everything I now have a segfault in Avalonia's initialization:
I will try a rebuild from scratch just in case. |
I have been able to rebuild Avalonia and test with the stable release. I can confirm that it's a different issue and that the original guess was correct. The deadlock happens with the following scenario:
Thread 1 needs all threads to finish their pending operations and the thread that is performing the rendering operations needs the GL Context lock to be released.
|
Try changing |
The issues does not reproduces with Is it possible that the AvnGlRenderingSession containing the SavedGlContext that holds the GL Context lock is hanging around and hasn't been explicitly disposed? |
Holding a native lock in one managed thread while attempting to take it from another is completely normal and expected scenario. Mono seems to not expect it by default for some reason, so it's a Mono issue. Since it's fixed by changing Mono's thread suspend mode I'm going to close the issue. |
Describe the bug
Avalonia 0.10.18 in macOS is causing a deadlock in mono's runtime during garbage collection. The GC is pausing the world in Thread 1 and waiting for all managed threads to finish pending operations. Meanwhile, in a managed thread, Avalonia's renderer is trying to acquire a lock for rendering in
AvnGlRenderTarget::BeginDrawing
that most likely needs to be released in Thread 1, causing a deadlock.To Reproduce
I haven't been to create a demo project to reproduce it, but I can consistently reproduce it in my application, although it's racy, when a I launch a new modal dialog in a new window.
Expected behavior
Mono does not deadlock in garbage collection
Screenshots
Desktop (please complete the following information):
Additional context
Deadlock in AvnGlRenderTarget::BeginDrawing trying to make the GL context current
``` * thread #1 * frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib`semaphore_wait_trap + 10 frame #1: 0x000000010565bef9 mono-sgen64`mono_os_sem_timedwait [inlined] mono_os_sem_wait at mono-os-semaphore.h:84:8 [opt] frame #2: 0x000000010565bef0 mono-sgen64`mono_os_sem_timedwait(sem=, timeout_ms=, flags=MONO_SEM_FLAGS_NONE) at mono-os-semaphore.h:103 [opt] frame #3: 0x000000010565b9b5 mono-sgen64`mono_threads_wait_pending_operations at mono-threads.c:319:8 [opt] frame #4: 0x00000001055fb123 mono-sgen64`sgen_client_stop_world at sgen-stw.c:306:3 [opt] frame #5: 0x00000001055fb10f mono-sgen64`sgen_client_stop_world(generation=0, serial_collection=0) at sgen-stw.c:124 [opt] frame #6: 0x000000010560e4e6 mono-sgen64`sgen_stop_world(generation=0, serial_collection=0) at sgen-gc.c:3871:2 [opt] frame #7: 0x000000010560b14d mono-sgen64`sgen_perform_collection [inlined] sgen_perform_collection_inner at sgen-gc.c:2566:3 [opt] frame #8: 0x000000010560b0e5 mono-sgen64`sgen_perform_collection(requested_size=2168, generation_to_collect=0, reason="Nursery full", forced_serial=0, stw=1) at sgen-gc.c:2679 [opt] frame #9: 0x000000010560b097 mono-sgen64`sgen_ensure_free_space(size=2168, generation=) at sgen-gc.c:2545:2 [opt] frame #10: 0x0000000105600e0d mono-sgen64`sgen_alloc_obj_nolock(vtable=0x00007fb8da30c4c0, size=2168) at sgen-alloc.c:258:6 [opt] frame #11: 0x00000001055fd7d1 mono-sgen64`mono_gc_alloc_vector(vtable=0x00007fb8da30c4c0, size=2168, max_length=89) at sgen-mono.c:1322:20 [opt] frame #12: 0x105b42636 (wrapper managed-to-native) object:__icall_wrapper_mono_gc_alloc_vector (intptr,intptr,intptr) [{0x7fb8cf043888} + 0xc6] (0x105b42570 0x105b4270a) [0x7fb8ceb042d0 - LongoMatch.exe]thread #2
frame #0: 0x00007ff803bb73ea libsystem_kernel.dylib
__psynch_cvwait + 10 frame #1: 0x00007ff803bf1a6f libsystem_pthread.dylib
_pthread_cond_wait + 1249frame #2: 0x0000000105641b1e mono-sgen64
thread_func [inlined] mono_os_cond_wait(mutex=<unavailable>) at mono-os-mutex.h:219:8 [opt] frame #3: 0x0000000105641b0b mono-sgen64
thread_func at sgen-thread-pool.c:165 [opt]frame #4: 0x0000000105641afd mono-sgen64
thread_func(data=0x0000000000000000) at sgen-thread-pool.c:196 [opt] frame #5: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125frame #6: 0x00007ff803becf6b libsystem_pthread.dylib`thread_start + 15
thread #3
frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib
semaphore_wait_trap + 10 frame #1: 0x00000001055ee6da mono-sgen64
finalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at mono-os-semaphore.h:84:8 [opt]frame #2: 0x00000001055ee6cf mono-sgen64
finalizer_thread at mono-coop-semaphore.h:41 [opt] frame #3: 0x00000001055ee6b5 mono-sgen64
finalizer_thread(unused=) at gc.c:965 [opt]frame #4: 0x00000001055acc4d mono-sgen64
start_wrapper [inlined] start_wrapper_internal at threads.c:1233:3 [opt] frame #5: 0x00000001055acc0a mono-sgen64
start_wrapper(data=0x00006000034989c0) at threads.c:1308 [opt]frame #6: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125 frame #7: 0x00007ff803becf6b libsystem_pthread.dylib
thread_start + 15thread #4
frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib
semaphore_wait_trap + 10 frame #1: 0x000000010565b808 mono-sgen64
mono_thread_info_wait_for_resume [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_NONE) at mono-os-semaphore.h:84:8 [opt]frame #2: 0x000000010565b7f9 mono-sgen64
mono_thread_info_wait_for_resume(info=0x00007fb8cf820000) at mono-threads.c:233 [opt] frame #3: 0x0000000105661c18 mono-sgen64
mono_threads_exit_gc_safe_region_unbalanced_internal(cookie=0x00007fb8cf820000, stackdata=) at mono-threads-coop.c:391:3 [opt]frame #4: 0x00000001054cab0f mono-sgen64
socket_transport_recv(buf=2001-01-01 00:00:00 UTC, len=11) at debugger-agent.c:1178:2 [opt] frame #5: 0x00000001054b9406 mono-sgen64
debugger_thread [inlined] transport_recv(len=11) at debugger-agent.c:1578:9 [opt]frame #6: 0x00000001054b93cd mono-sgen64
debugger_thread(arg=<unavailable>) at debugger-agent.c:10196 [opt] frame #7: 0x00000001055acc4d mono-sgen64
start_wrapper [inlined] start_wrapper_internal at threads.c:1233:3 [opt]frame #8: 0x00000001055acc0a mono-sgen64
start_wrapper(data=0x0000600003498a40) at threads.c:1308 [opt] frame #9: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125frame #10: 0x00007ff803becf6b libsystem_pthread.dylib`thread_start + 15
thread #5
frame #0: 0x00007ff803bb497a libsystem_kernel.dylib
mach_msg_trap + 10 frame #1: 0x00007ff803bb4ce8 libsystem_kernel.dylib
mach_msg + 56frame #2: 0x00007ff803cb7cdd CoreFoundation
__CFRunLoopServiceMachPort + 319 frame #3: 0x00007ff803cb6368 CoreFoundation
__CFRunLoopRun + 1276frame #4: 0x00007ff803cb57ac CoreFoundation
CFRunLoopRunSpecific + 562 frame #5: 0x00007ff806849f5e AppKit
_NSEventThread + 132frame #6: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125 frame #7: 0x00007ff803becf6b libsystem_pthread.dylib
thread_start + 15thread #6
frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib
semaphore_wait_trap + 10 frame #1: 0x000000010565b808 mono-sgen64
mono_thread_info_wait_for_resume [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_NONE) at mono-os-semaphore.h:84:8 [opt]frame #2: 0x000000010565b7f9 mono-sgen64
mono_thread_info_wait_for_resume(info=0x00007fb8d48bfc00) at mono-threads.c:233 [opt] frame #3: 0x0000000105661c18 mono-sgen64
mono_threads_exit_gc_safe_region_unbalanced_internal(cookie=0x00007fb8d48bfc00, stackdata=) at mono-threads-coop.c:391:3 [opt]frame #4: 0x00000001055b9516 mono-sgen64
mono_w32handle_timedwait_signal_handle at mono-coop-mutex.h:105:2 [opt] frame #5: 0x00000001055b94dc mono-sgen64
mono_w32handle_timedwait_signal_handle [inlined] mono_w32handle_timedwait_signal_naked(poll=0, alerted=) at w32handle.c:652 [opt]frame #6: 0x00000001055b94dc mono-sgen64
mono_w32handle_timedwait_signal_handle(handle_data=<unavailable>, timeout=<unavailable>, poll=0, alerted=<unavailable>) at w32handle.c:767 [opt] frame #7: 0x00000001055b93d1 mono-sgen64
mono_w32handle_wait_one(handle=, timeout=, alertable=) at w32handle.c:892:13 [opt]frame #8: 0x00000001055b9649 mono-sgen64
mono_w32handle_wait_multiple(handles=0x000070000e685860, nhandles=1, waitall=0, timeout=<unavailable>, alertable=1, error=0x000070000e685708) at w32handle.c:1002:10 [opt] frame #9: 0x00000001055a623d mono-sgen64
ves_icall_System_Threading_WaitHandle_Wait_internal(handles=, numhandles=, waitall=, timeout=-1, error=0x000070000e685708) at threads.c:2314:9 [opt]frame #10: 0x000000010553f308 mono-sgen64
ves_icall_System_Threading_WaitHandle_Wait_internal_raw(a0=0x000070000e685860, a1=1, a2='\0', a3=11) at icall-def.h:1100:1 [opt] frame #11: 0x0000000118f7f8f1 frame #12: 0x0000000118f7f0db frame #13: 0x0000000118f7b4ba frame #14: 0x0000000118f79383 frame #15: 0x0000000105372352 mono-sgen64
mono_jit_runtime_invoke(method=, obj=, params=0x000070000e685f68, exc=, error=) at mini-runtime.c:3217:12 [opt]frame #16: 0x0000000105581e07 mono-sgen64
mono_runtime_invoke_checked [inlined] do_runtime_invoke(method=<unavailable>, obj=0x0000000105fcff78, params=0x000070000e685f68, exc=<unavailable>, error=0x000070000e685f18) at object.c:3052:11 [opt] frame #17: 0x0000000105581dd2 mono-sgen64
mono_runtime_invoke_checked(method=0x00007fb8d4965980, obj=0x0000000105fcff78, params=0x000070000e685f68, error=0x000070000e685f18) at object.c:3220 [opt]frame #18: 0x0000000105588700 mono-sgen64
mono_runtime_delegate_try_invoke(delegate=0x0000000105fcff78, params=0x000070000e685f68, exc=0x0000000000000000, error=0x000070000e685f18) at object.c:4438:7 [opt] frame #19: 0x00000001055acc8d mono-sgen64
start_wrapper at threads.c:1255:3 [opt]frame #20: 0x00000001055acc0a mono-sgen64
start_wrapper(data=0x00006000034fa580) at threads.c:1308 [opt] frame #21: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125frame #22: 0x00007ff803becf6b libsystem_pthread.dylib`thread_start + 15
thread #7
frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib
semaphore_wait_trap + 10 frame #1: 0x000000010565b808 mono-sgen64
mono_thread_info_wait_for_resume [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_NONE) at mono-os-semaphore.h:84:8 [opt]frame #2: 0x000000010565b7f9 mono-sgen64
mono_thread_info_wait_for_resume(info=0x00007fb8d4a45c00) at mono-threads.c:233 [opt] frame #3: 0x0000000105661c18 mono-sgen64
mono_threads_exit_gc_safe_region_unbalanced_internal(cookie=0x00007fb8d4a45c00, stackdata=) at mono-threads-coop.c:391:3 [opt]frame #4: 0x000000010565e459 mono-sgen64
mono_thread_info_sleep at mono-coop-mutex.h:93:2 [opt] frame #5: 0x000000010565e419 mono-sgen64
mono_thread_info_sleep [inlined] sleep_interruptable(ms=, alerted=) at mono-threads.c:1643 [opt]frame #6: 0x000000010565e393 mono-sgen64
mono_thread_info_sleep(ms=500, alerted=<unavailable>) at mono-threads.c:1673 [opt] frame #7: 0x00000001054e4092 mono-sgen64
monitor_thread(unused=) at threadpool-worker-default.c:728:8 [opt]frame #8: 0x00000001055acc4d mono-sgen64
start_wrapper [inlined] start_wrapper_internal at threads.c:1233:3 [opt] frame #9: 0x00000001055acc0a mono-sgen64
start_wrapper(data=0x000060000342a980) at threads.c:1308 [opt]frame #10: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125 frame #11: 0x00007ff803becf6b libsystem_pthread.dylib
thread_start + 15thread #8
frame #0: 0x00007ff803bb49b6 libsystem_kernel.dylib
semaphore_wait_trap + 10 frame #1: 0x000000010565b808 mono-sgen64
mono_thread_info_wait_for_resume [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_NONE) at mono-os-semaphore.h:84:8 [opt]frame #2: 0x000000010565b7f9 mono-sgen64
mono_thread_info_wait_for_resume(info=0x00007fb8d2863400) at mono-threads.c:233 [opt] frame #3: 0x0000000105661c18 mono-sgen64
mono_threads_exit_gc_safe_region_unbalanced_internal(cookie=0x00007fb8d2863400, stackdata=) at mono-threads-coop.c:391:3 [opt]frame #4: 0x00000001054e45b6 mono-sgen64
worker_thread at mono-coop-semaphore.h:57:2 [opt] frame #5: 0x00000001054e44da mono-sgen64
worker_thread at threadpool-worker-default.c:388 [opt]frame #6: 0x00000001054e4430 mono-sgen64
worker_thread(unused=<unavailable>) at threadpool-worker-default.c:490 [opt] frame #7: 0x00000001055acc4d mono-sgen64
start_wrapper [inlined] start_wrapper_internal at threads.c:1233:3 [opt]frame #8: 0x00000001055acc0a mono-sgen64
start_wrapper(data=0x0000600003425e40) at threads.c:1308 [opt] frame #9: 0x00007ff803bf14e1 libsystem_pthread.dylib
_pthread_start + 125frame #10: 0x00007ff803becf6b libsystem_pthread.dylib`thread_start + 15
thread #9
frame #0: 0x00007ff803bb6bd2 libsystem_kernel.dylib
__psynch_mutexwait + 10 frame #1: 0x00007ff803beee7e libsystem_pthread.dylib
_pthread_mutex_firstfit_lock_wait + 76frame #2: 0x00007ff803beccbb libsystem_pthread.dylib
_pthread_mutex_firstfit_lock_slow + 205 frame #3: 0x00007ffa1bc98d00 OpenGL
CGLLockContext + 34frame #4: 0x00000001190bd909 libAvaloniaNative.dylib
AvnGlContext::MakeCurrent(IUnknown**) + 75 frame #5: 0x00000001190bcda5 libAvaloniaNative.dylib
AvnGlRenderTarget::BeginDrawing(IAvnGlSurfaceRenderingSession**) + 113frame #6: 0x000000011b880ecb
mono-sgen64 was compiled with optimization - stepping may behave oddly; variables may not be available.
frame #7: 0x000000011b87f99a
frame #8: 0x000000011b83a93d
[...]
```
Deadlock in AvnGlRenderTarget::BeginDrawing acquiring the `IAvnGlSurfaceRenderingSession` lock
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: