Loghorn / ant-plus

A node module for ANT+
MIT License
138 stars 67 forks source link

Samples crashing with cryptic stack trace #47

Closed hallgchris closed 2 years ago

hallgchris commented 2 years ago

Hi! I'm having trouble running the samples for this library. I can only assume it's something weird with my setup, yet this issue occurs both on my linux PC and my raspberry pi.

When I run sample.js on my PC, I get this ugly crash:

node[4071]: ../src/node_api.cc:1149:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
 1: 0xa03520 node::Abort() [node]
 2: 0xa0359e  [node]
 3: 0x9d706a  [node]
 4: 0x7f90bda8ba28 Device::Close(Napi::CallbackInfo const&) [/home/chris/git/ant-plus/node_modules/usb/prebuilds/linux-x64/node.napi.glibc.node]
 5: 0x7f90bda947ca Napi::InstanceWrap<Device>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*) [/home/chris/git/ant-plus/node_modules/usb/prebuilds/linux-x64/node.napi.glibc.node]
 6: 0x9b8c8f  [node]
 7: 0xbe359b  [node]
 8: 0xbe4b46  [node]
 9: 0xbe51c6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x13ff159  [node]
[1]    4071 abort (core dumped)  node sample/sample.js

To be totally honest, I've no idea what's happening here. Any pointers would be welcome.

Curiously, on my PC, this only occurs after the first time I plug in the ANT+ dongle. If I unplug and replug it, the script works as expected. However, I get a very similar crash on my raspberry pi, and replugging the dongle does not seem to make a difference here. This is the exact crash I get on the Pi:

node[6930]: ../src/node_api.cc:1275:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
Aborted

Looks like it's the same issue.

I have tried various node versions (14, 17) and multiple ant+ dongles. The same issue is also present on my laptop which is similarly set up to my desktop. I feel crazy that I'm having this issue on 3 computers yet I'm struggling to find any evidence of similar problems! Any pointers big or small would be hugely appreciated. Let me know if I can provide more info too!

hallgchris commented 2 years ago

Silly me, turned out to be a permissions problem. Ran totally fine with sudo. Longer-term I'm using this solution so that it runs from the pi user. Hope this helps someone in the future!