hammerspoon: crash in coroutine (0.9.84 as well as master) - EXC_CRASH (SIGABRT) EXC_CORPSE_NOTIFY
Not sure how to best report this so I’m going to lay out some stuff and hope we can narrow it down. @asmagill and @cmsj really hoping you can take a peek here.
- macOS 11.2.3
- Hammerspoon 0.9.84, also tested w/ a debug build compiled from master 3/8/2021
I’ve been working on a module that creates floating live preview windows. It’s basically done, the only major issue I’m having now is – the darned thing is crashing constantly. I believe this is due to the use of coroutines. @asmagill 's amazing code got me started and I’ve adapted and added to get where I am today, which I just put up here:
gist: float.lua
I found 2 long threads (https://github.com/Hammerspoon/hammerspoon/issues/2339 and https://github.com/Hammerspoon/hammerspoon/issues/2306) about various breakage with coroutines and so my assumption here is that this is an edge case in there somewhere.
Here is my pretty reliable method for crashing this:
- start the preview
- right-click and hold, drag and pan around
- while dragging, hit <kbd>CTRL</kbd>+<kbd>PrtScr</kbd> to cycle thru the refresh intervals
- faster refresh rates seem to trigger this more easily, so leave it at 0.05s
- release the right mouse button while the cursor is positioned within the canvas
- here is where it usually crashes.
- if it doesn’t crash immediately, repeat from step 2
- after 2-3 cycles of this, I can reliably crash HS about 90% of the time
I initally thought this was a plain-jane memory leak because we are pumping a lot of bits with all the screen capturing going on 20x per second and calling lots of hs.image routines with the snapping and cropping. I added a manual garbage collector in there to keep memory from ballooning (before that, memory use was growing out of control quickly). Now it hovers between 200MB-500MB which is reasonable.
The typical crash dump looks like this (I have about 30 of these saved now in case you want to see them). I uploaded one recent one here: https://gist.github.com/luckman212/a6ffb75e57a27835f4f24b62056bc0bb I wish I knew what to do with this or how to enable more detailed debug logging.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
abort() called
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff205a5462 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff205d3610 pthread_kill + 263
2 libsystem_c.dylib 0x00007fff20526720 abort + 120
3 org.hammerspoon.Hammerspoon 0x000000010493adb8 -[SentryCrashExceptionApplication _crashOnException:] + 58
4 com.apple.AppKit 0x00007fff23295bd7 -[NSApplication reportException:] + 733
5 org.hammerspoon.Hammerspoon 0x000000010493ad51 -[SentryCrashExceptionApplication reportException:] + 371
6 com.apple.AppKit 0x00007fff23349068 uncaughtErrorProc + 145
7 org.hammerspoon.Hammerspoon 0x000000010494453f handleException + 720
8 org.hammerspoon.Hammerspoon 0x000000010493ad23 -[SentryCrashExceptionApplication reportException:] + 325
9 com.apple.AppKit 0x00007fff22eda73d -[NSApplication run] + 765
10 com.apple.AppKit 0x00007fff22eae96f NSApplicationMain + 816
11 libdyld.dylib 0x00007fff205ee621 start + 1
For anyone who wants to test, just edit your prefs (at the top) and then require it from your init.lua or separately. Once you activate, there are some Features:
- You can hit the main hotkey (default <kbd>PrtScr</kbd>) repeatedly to cycle through various user-settable window sizes.
- You can move the preview with a left-click and drag.
- You can pan around the underlying window by right-clicking and dragging (inverse scrolling is also an option in prefs)
- A crosshair will be shown while panning, to help with positioning.
- Customize whether the window gets tucked away out of sight or remains in place (
moveOffscreen) - Cycle thru various refresh intervals with <kbd>CTRL</kbd>+<kbd>PrtScr</kbd>. Default = 0.25s or 4x per second. Faster uses more CPU but smoother for watching video etc.
- Live Preview will auto-pause if the source window is minimized (can’t capture non-visible windows) and resume when restored
- Double-click the preview window to bring the parent app forward and reveal the window.
- Customize colors, font size etc.
- Preview will auto-close if source window disappears (optional: receive notification when this happens - see
notifyOnClose) - Since the canvas doesn’t fire the callback if the
mouseUpevent occurs while the cursor is outside of the canvas rect, I added an <kbd>ESC</kbd> hotkey to bail out of the coroutine if it gets “stuck” like that.
I would love some additional testing & feedback on this. Really hope I can eliminate these crashes!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (18 by maintainers)
I can’t test this until later tonight, but looking at the sentry entry and the source for canvas, I think the issue might be at https://github.com/Hammerspoon/hammerspoon/blob/0a89aceca766182ac3c258fc43090ab574e502f7/extensions/canvas/internal.m#L1825 which should probably be
>=instead of>. If you get a chance to try it in a development build, let me know if it helps… I want to try and see if I can trigger the crash first when I get home and can try running your specific sample code.@luckman212 are you on a Mac Mini by any chance? If so this would be https://sentry.io/share/issue/ff3c8e14d3c14e14bb70b8ce44d1859f/
@asmagill Your fix is holding steady 🙌 I fixed the infinite loop in my gist too if you want to play around.
Ok, well that gets us the traceback we actually need, but it’s code I’m not very familiar with, so hopefully @asmagill can take a look when he gets some time 😃