kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.62k stars 987 forks source link

CVDisplayLink deadlock on macOS #1779

Closed zthompson47 closed 5 years ago

zthompson47 commented 5 years ago

On a rare occasion kitty will freeze with the macOS "spinning beachball" when I switch between kitty and another app (Firefox usually), both in fullscreen mode. It's happened maybe three other times in a couple of months of using kitty on a regular basis. I'm using the same system that caused #1761 - a MacBook Pro (Retina, 13-inch, Late 2013).

This time I was ready with "/usr/bin/sample" and have a stack trace. I was using the latest kitty release version, so debugging symbols, unfortunately. I tried to force quit kitty while sample was running, but I don't think I did it before sample produced this stack trace (it sampled for 10 seconds by default). I removed indentation for Thread_37453 to make it readable:

Analysis of sampling kitty (pid 2037) every 1 millisecond
Process:         kitty [2037]
Path:            /Applications/kitty.app/Contents/MacOS/kitty
Load Address:    0x102a1c000
Identifier:      net.kovidgoyal.kitty
Version:         0.14.2 (0.14.2)
Code Type:       X86-64
Parent Process:  ??? [1]

Date/Time:       2019-07-05 06:32:36.242 -0400
Launch Time:     2019-07-04 07:33:29.234 -0400
OS Version:      Mac OS X 10.14.5 (18F132)
Report Version:  7
Analysis Tool:   /usr/bin/sample

Physical footprint:         229.2M
Physical footprint (peak):  234.0M
----

Call graph:
    8989 Thread_37453   DispatchQueue_1: com.apple.main-thread  (serial)
    8989 start  (in libdyld.dylib) + 1  [0x7fff632003d5]
    8989 main  (in kitty) + 1291  [0x102a1d97b]
    8989 PyObject_CallMethod  (in Python) + 187  [0x102a4612b]
    8989 _PyObject_CallFunctionVa  (in Python) + 223  [0x102a45e9f]
    8989 _PyFunction_FastCallDict  (in Python) + 450  [0x102a44802]
    8989 _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 _PyFunction_FastCallKeywords  (in Python) + 230  [0x102a44d26]
    8989 _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 617  [0x102b0e859]
    8989 _PyCFunction_FastCallKeywords  (in Python) + 44  [0x102a44d6c]
    8989 _PyMethodDef_RawFastCallKeywords  (in Python) + 686  [0x102a4599e]
    8989 builtin_exec  (in Python) + 563  [0x102b033b3]
    8989 PyEval_EvalCode  (in Python) + 48  [0x102b05c70]
    8989 _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 function_code_fastcall  (in Python) + 210  [0x102a45232]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 function_code_fastcall  (in Python) + 210  [0x102a45232]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 function_code_fastcall  (in Python) + 210  [0x102a45232]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 _PyFunction_FastCallKeywords  (in Python) + 230  [0x102a44d26]
    8989 _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
    8989 call_function  (in Python) + 726  [0x102b0e8c6]
    8989 _PyFunction_FastCallKeywords  (in Python) + 230  [0x102a44d26]
    8989 _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]
    8989 _PyEval_EvalFrameDefault  (in Python) + 5062  [0x102b070d6]
    8989 call_function  (in Python) + 764  [0x102b0e8ec]
    8989 _PyMethodDescr_FastCallKeywords  (in Python) + 82  [0x102a4b452]
    8989 _PyMethodDef_RawFastCallKeywords  (in Python) + 798  [0x102a45a0e]
    8989 ???  (in fast_data_types.so)  load address 0x10308d000 + 0x23d4f  [0x1030b0d4f]
    8989 -[NSApplication run]  (in AppKit) + 699  [0x7fff3495483c]
    8989 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]  (in AppKit) + 1361  [0x7fff3495a71f]
    8989 _DPSNextEvent  (in AppKit) + 965  [0x7fff3495b987]
    8989 _BlockUntilNextEventMatchingListInModeWithFilter  (in HIToolbox) + 64  [0x7fff365c1436]
    8989 ReceiveNextEventCommon  (in HIToolbox) + 603  [0x7fff365c16a5]
    8989 RunCurrentEventLoopInMode  (in HIToolbox) + 292  [0x7fff365c196b]
    8989 CFRunLoopRunSpecific  (in CoreFoundation) + 455  [0x7fff372d58be]
    8989 __CFRunLoopRun  (in CoreFoundation) + 2772  [0x7fff372d65e4]
    8989 __CFRunLoopDoBlocks  (in CoreFoundation) + 394  [0x7fff372d6887]
    8989 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__  (in CoreFoundation) + 12  [0x7fff37313164]
    8989 ___NSMainRunLoopPerformBlockInModes_block_invoke  (in AppKit) + 25  [0x7fff3548b10f]
    8989 -[NSApplication(ScreenHandling) _reactToScreenInvalidationImmediately:]  (in AppKit) + 354  [0x7fff3548aaf5]
    8989 -[NSNotificationCenter postNotificationName:object:userInfo:]  (in Foundation) + 66  [0x7fff3952f06b]
    8989 _CFXNotificationPost  (in CoreFoundation) + 732  [0x7fff372a9737]
    8989 -[_CFXNotificationRegistrar find:object:observer:enumerator:]  (in CoreFoundation) + 1642  [0x7fff372aa384]
    8989 ___CFXNotificationPost_block_invoke  (in CoreFoundation) + 87  [0x7fff37341928]
    8989 _CFXRegistrationPost  (in CoreFoundation) + 404  [0x7fff3733947a]
    8989 ___CFXRegistrationPost_block_invoke  (in CoreFoundation) + 63  [0x7fff37339510]
    8989 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__  (in CoreFoundation) + 12  [0x7fff37339596]
    8989 ???  (in glfw-cocoa.so)  load address 0x105548000 + 0x1052e  [0x10555852e]
    8989 CVDisplayLink::stop()  (in CoreVideo) + 25  [0x7fff39042f3b]
    8989 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 222  [0x7fff633f24cd]
    8989 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 96  [0x7fff633f4d52]
    8989 __psynch_mutexwait  (in libsystem_kernel.dylib) + 10  [0x7fff63337f06]

    8989 Thread_37491: com.apple.NSEventThread
    + 8989 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff633f340d]
    +   8989 _pthread_start  (in libsystem_pthread.dylib) + 66  [0x7fff633f7249]
    +     8989 _pthread_body  (in libsystem_pthread.dylib) + 126  [0x7fff633f42eb]
    +       8989 _NSEventThread  (in AppKit) + 175  [0x7fff349636a6]
    +         8989 CFRunLoopRunSpecific  (in CoreFoundation) + 455  [0x7fff372d58be]
    +           8989 __CFRunLoopRun  (in CoreFoundation) + 1612  [0x7fff372d615c]
    +             8989 __CFRunLoopServiceMachPort  (in CoreFoundation) + 328  [0x7fff372d6bee]
    +               8989 mach_msg  (in libsystem_kernel.dylib) + 60  [0x7fff6333576c]
    +                 8989 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff6333522a]
    8989 Thread_37496: KittyChildMon
    + 8989 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff633f340d]
    +   8989 _pthread_start  (in libsystem_pthread.dylib) + 66  [0x7fff633f7249]
    +     8989 _pthread_body  (in libsystem_pthread.dylib) + 126  [0x7fff633f42eb]
    +       8989 ???  (in fast_data_types.so)  load address 0x10308d000 + 0x27dd0  [0x1030b4dd0]
    +         8989 poll  (in libsystem_kernel.dylib) + 10  [0x7fff6333d36e]
    8989 Thread_213211: CVDisplayLink
    + 8989 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff633f340d]
    +   8989 _pthread_start  (in libsystem_pthread.dylib) + 66  [0x7fff633f7249]
    +     8989 _pthread_body  (in libsystem_pthread.dylib) + 126  [0x7fff633f42eb]
    +       8989 CVDisplayLink::runIOThread()  (in CoreVideo) + 626  [0x7fff39042362]
    +         8989 CVDisplayLink::performIO(CVTimeStamp*)  (in CoreVideo) + 233  [0x7fff39042e8d]
    +           8989 ???  (in glfw-cocoa.so)  load address 0x105548000 + 0x10e6e  [0x105558e6e]
    +             8989 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 222  [0x7fff633f24cd]
    +               8989 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 96  [0x7fff633f4d52]
    +                 8989 __psynch_mutexwait  (in libsystem_kernel.dylib) + 10  [0x7fff63337f06]
    8989 Thread_213297
      8989 start_wqthread  (in libsystem_pthread.dylib) + 13  [0x7fff633f33fd]
        8989 _pthread_wqthread  (in libsystem_pthread.dylib) + 458  [0x7fff633f3636]
          8989 __workq_kernreturn  (in libsystem_kernel.dylib) + 10  [0x7fff63336bfe]

Total number in stack (recursive counted multiple, when >=5):
        7       _PyEval_EvalFrameDefault  (in Python) + 5233  [0x102b07181]
        6       call_function  (in Python) + 726  [0x102b0e8c6]
        5       _PyEval_EvalCodeWithName  (in Python) + 2769  [0x102b0f521]

Sort by top of stack, same collapsed (when >= 5):
        __psynch_mutexwait  (in libsystem_kernel.dylib)        17978
        __workq_kernreturn  (in libsystem_kernel.dylib)        8989
        mach_msg_trap  (in libsystem_kernel.dylib)        8989
        poll  (in libsystem_kernel.dylib)        8989
larissa commented 5 years ago

I've been having the same issue. Just wanted to thank Kovid for being so responsive and fixing so quickly 🥇

kovidgoyal commented 5 years ago

You're welcome :)