node-midi: Crashing with assertion/segmentation fault/bus error
Issuing new (require('midi')).input().getPortCount(); in a node repl gives me one of the following:
Assertion failed: (0), function uv_close, file ../deps/uv/src/unix/core.c, line 165. Abort trap: 6
Segmentation fault: 11
Bus error 10
But only after using the repl for a while. Easiest way for me to reproduce is by repeatedly pressing enter some 30 times.
Can reproduce on Mac running OS X 10.11.2, node v5.4.0 and on a Raspberry Pi running Linux 4.1.13, node v4.2.1.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 31 (2 by maintainers)
@grav Here’s an example, hacked down a bit so it only depends on node-midi, child_process, and segfault-handler.
midispawn.js
midiinchild.js
midioutchild.js
Happy days. Reopen if it comes back!
Found a workaround that may be an additional clue to solve the bug. I can create many midi inputs and still create a midi output without crashing, in a raspberry PI B model 3, by making a new process, using the node js child_process
I created a parent, that besides making many midi outputs, it does the following:
Then, the midiInputWorkaround.js file contains:
The for loop is there as “decoration” because when the library gets fixed, I can copy the code back. In my context, it will only make one midi input. As test, I fed a stream of clock messages into the midi input. If I turn a CC knob, it crashes.
I’ve found a workaround, at least for my problem: All calls to input() and output() must be closed if unused:
I can get away without calling
openPort, but thenclosePortends up printing an error message.I’m circumventing this for the moment by forking input and output into child processes and respawning when a child process crashes. Seems to work although I haven’t thoroughly tested what or how many messages are dropped. Latency seems fine, surprisingly. 100% of crashes are on the input handling process, and it seems to me there is an issue with the callback handling.