Skip to content
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

Xcode autocomplete popups causing crashes #580

Closed
OberstKrueger opened this issue Jun 17, 2020 · 3 comments
Closed

Xcode autocomplete popups causing crashes #580

OberstKrueger opened this issue Jun 17, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@OberstKrueger
Copy link

While working in Xcode, popover autocompletion hints are causing excessive crashing in yabai. Nothing else in Xcode seems to cause it, only when typing in code and seeing those popovers appear and disappear quickly.

It started happening with yabai version 3.1.2.
Xcode version is 11.5, on macOS 10.15.5.

Output from yabai --verbose after switching to the window and typing up code that causes the popup:
thread: 70410240 | EVENT_HANDLER_WINDOW_TITLE_CHANGED: Xcode 20259
thread: 70410240 | window_manager_create_and_add_window: Xcode 20261
thread: 70410240 | EVENT_HANDLER_WINDOW_DESTROYED: Xcode 20261
Segmentation fault: 11

I can get more detailed debug logs later if necessary.

@dominiklohmann
Copy link
Collaborator

I managed to reproduce this while running yabai in lldb. It appears to be a timing issue.

thread: 266219520 | window_manager_create_and_add_window: Xcode 13373
thread: 266219520 | EVENT_HANDLER_WINDOW_DESTROYED: Xcode 13373
thread: 266219520 | event_signal_transmit: transmitting window_destroyed to 1 subscriber(s)
thread: 266219520 | EVENT_HANDLER_DAEMON_MESSAGE: query --windows --space
thread: 266219520 | window_manager_create_and_add_window: Xcode 13374
thread: 266219520 | EVENT_HANDLER_WINDOW_DESTROYED: Xcode 13374
thread: 266219520 | event_signal_transmit: transmitting window_destroyed to 1 subscriber(s)
Process 63811 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x000000010001574f yabai`application_notification_handler(observer=0x000000010036e360, element=0x0000000100615530, notification=@"AXUIElementDestroyed", context=0x00000001006109e0) at application.c:14:30
   11  	        uint32_t *window_id_ptr = *(uint32_t **) context;
   12  	        if (!window_id_ptr) return;
   13
-> 14  	        uint32_t window_id = *window_id_ptr;
   15  	        while (!__sync_bool_compare_and_swap((uint32_t **) context, window_id_ptr, NULL));
   16
   17  	        struct event *event = event_create(&g_event_loop, WINDOW_DESTROYED, (void *)(uintptr_t) window_id);
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x000000010001574f yabai`application_notification_handler(observer=0x000000010036e360, element=0x0000000100615530, notification=@"AXUIElementDestroyed", context=0x00000001006109e0) at application.c:14:30
    frame #1: 0x00007fff2dd7cf7e HIServices`_XXMIGPostNotification + 717
    frame #2: 0x00007fff2dda2b03 HIServices`_XPostNotification + 340
    frame #3: 0x00007fff2dd5ff64 HIServices`mshMIGPerform + 174
    frame #4: 0x00007fff2faa9394 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    frame #5: 0x00007fff2faa92e0 CoreFoundation`__CFRunLoopDoSource1 + 541
    frame #6: 0x00007fff2faa7e09 CoreFoundation`__CFRunLoopRun + 2270
    frame #7: 0x00007fff2faa6ece CoreFoundation`CFRunLoopRunSpecific + 462
    frame #8: 0x00007fff2fb2f519 CoreFoundation`CFRunLoopRun + 40
    frame #9: 0x00000001000203d9 yabai`main(argc=2, argv=0x00007ffeefbff068) at yabai.c:328:5
    frame #10: 0x00007fff69aa3cc9 libdyld.dylib`start + 1
    frame #11: 0x00007fff69aa3cc9 libdyld.dylib`start + 1

@dominiklohmann dominiklohmann added the bug Something isn't working label Jun 17, 2020
@koekeishiya
Copy link
Owner

koekeishiya commented Jun 17, 2020

macOS APIs are such garbage, I quit.

# notification from macOS, UIElement destroyed
# CAS operation
context = 0x7f8931530fb0, window_id_ptr = 0x7f8931530d44, NEW window_id_ref = 0x0 
window_id = 13493

# we verify here that the above CAS did succeed and perform cleanup
EVENT_HANDLER_WINDOW_DESTROYED: Xcode 13493 0x7f8931530fb0 0x0

# somehow randomly for fun we get another window destroyed event 
# for the same window after  we have told macOS that we are not 
# interested in notifications AND destroyed all memory.
# Our previous atomic operations are thus rendered useless when we get here.. 
# Why do we even get here..
context = 0x7f8931530fb0, window_id_ptr = 0x8000000000000000, NEW window_id_ref = 0x0
(These values, with the exception of context, are all garbage because we freed everything in the step above).

koekeishiya added a commit that referenced this issue Jun 17, 2020
@koekeishiya koekeishiya added the addressed on master; not released Fixed upstream, but not yet released label Jun 17, 2020
@koekeishiya
Copy link
Owner

I changed to some async versions of the AXNotification API because they performed better, but obviously that causes race conditions when they spin off the same notification multiple times for the same entity. Went back to using the old versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants