hammerspoon: Hammerspoon crash caused by calling hs.serial.deviceCallback() and reloading

I am finding that my Hammerspoon crashes whenever I try to use the hs.serial.deviceCallback function. Indeed, I was able to replicate the crash on two separate Macs (both M1 Mac minis), by simply using an init.lua file with the following contents:

hs.serial.deviceCallback(function(devices)
end)

After loading that init.lua, Hammerspoon launches OK, but then the next time Hammerspoon is reloaded, it crashes.

It’s possible that it’s an M1 issue; I’ll try it on my Intel Mac at home when I get a chance. If there’s any other information needed to debug, I’ll do my best to get it.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks so much guys, sorry I wasn’t able to contribute much! Love Hammerspoon, and love the developers!

attached PR fixes the crash at least. I’m not sure I have any serial port devices to test it with though!

The line in question is:

watcherDeviceManager.deviceCallbackRef = [skin luaUnref:refTable ref:watcherDeviceManager.deviceCallbackRef];

but that line doesn’t make a lot of sense, because it can be called right after watcherDeviceManager is created, at which point deviceCallbackRef would be LUA_NOREF which is a fatal error if passed to luaUnref::.

I also note that watcherDeviceManager is not stopped/deallocated in meta_gc, which means that across reloads its state is inconsistent because it may retain Lua references that no longer exist, and its gcCanary will be stale.