Julusian / node-midi

A node.js wrapper for RtMidi providing MIDI I/O
https://www.npmjs.com/package/@julusian/midi
MIT License
20 stars 7 forks source link

Segmentation fault in WSL2 #3

Closed hrueger closed 1 year ago

hrueger commented 1 year ago

Hi @Julusian, it's me again. I've just ran into a very strange issue: On my Windows 10 PC with Ubuntu in WSL2, I get a Segmentation Fault every time I try to list the Inputs.

It's very easy to reproduce:

const easymidi = require("easymidi")
try {
    console.log(easymidi.getInputs())
} catch {}

I'd like this to just return nothing or fail, so that I can catch the error. However, I get the following:

hannes@Hannes-Desktop:~/tests$ node
Welcome to Node.js v16.18.1.
Type ".help" for more information.
> const easymidi = require("easymidi")
undefined
> try { easymidi.getInputs() } catch {  }
ALSA lib seq_hw.c:466:(snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory

MidiInAlsa::initialize: error creating ALSA sequencer client object.

undefined
> Segmentation fault

Segmentation Fault happens about 1s after the try ... catch call.

It's fine for me that MIDI is not working inside WSL (that's probably an issue of my setup, I haven't really looked into this yet, but it shouldn't crash so hard.

This happens with Ubuntu on WSL2 on Windows 10:

hannes@Hannes-Desktop:~/tests$ uname -a
Linux Hannes-Desktop 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
hannes@Hannes-Desktop:~/tests$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Interestingly, on my Windows 11 machine, it works just fine (meaning getInputs() throws an error but does not crash with Segmentation Fault.

Do you have any idea?

hrueger commented 1 year ago

Hm, after some more playing around, it now also crashes with Segmentation Fault in WSL2 on Windows 11. The first time I've tried it, it didn't crash. I tried to get the inputs 5 or 6 times. The next time, it crashed shortly after printing undefined. Now, it almost always crashes.

hrueger commented 1 year ago

I was able to get the following using segfault-handler. Hope that helps

PID 19694 received SIGSEGV for address: 0x0
/home/hannes/tests/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x370d)[0x7f40acb3370d]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f40af38c520]
/home/hannes/tests/node_modules/@julusian/midi/prebuilds/midi-linux-x64/node-napi-v7.node(_ZN13NodeMidiInput7cleanupEv+0x10)[0x7f409dc14ec0]
/home/hannes/tests/node_modules/@julusian/midi/prebuilds/midi-linux-x64/node-napi-v7.node(_ZN13NodeMidiInputD2Ev+0x30)[0x7f409dc14fa0]
/home/hannes/tests/node_modules/@julusian/midi/prebuilds/midi-linux-x64/node-napi-v7.node(_ZN4Napi10ObjectWrapI13NodeMidiInputE16FinalizeCallbackEP10napi_e>node(_ZN4node13CallbackQueueIvJPNS_11EnvironmentEEE12CallbackImplIZN15node_napi_env__13CallFinalizerILb1EEEvPFvP10napi_env__PvS9_ES9_S9_EUlS2_E0_E4CallES2_>node(_ZN4node11Environment27RunAndClearNativeImmediatesEb+0x1bc)[0xa8ac3c]
node[0xa8b1fc]
node[0x154ca06]
node[0x155f134]
node(uv_run+0x138)[0x154d358]
node(_ZN4node13SpinEventLoopEPNS_11EnvironmentE+0x145)[0xa43975]
node(_ZN4node16NodeMainInstance3RunEv+0x186)[0xb487e6]
node(_ZN4node5StartEiPPc+0x9c)[0xacd2ac]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f40af373d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f40af373e40]
node[0xa4080c]

Unfortunately, Sentry is somehow not able to catch that, so I can't get those nicely formatted crash reports.

Julusian commented 1 year ago

This should be fixed now in v3.0.0

hrueger commented 1 year ago

Can confirm that the bug is resolved now, thanks a ton!