Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating midi.input() instances can cause ALSA to run out of resources #118

Open
simonbates opened this issue Nov 14, 2016 · 0 comments
Open
Labels

Comments

@simonbates
Copy link

If I create enough midi.input() instances, I eventually run out of ALSA resources on Linux and my program terminates.

For example, running the following program:

var midi = require("midi");

for (var i = 0; i < 100; i++) {
    new midi.input();
}

process.exit();

Results in:

ALSA lib seq_hw.c:457:(snd_seq_hw_open) open /dev/snd/seq failed: Cannot allocate memory

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

terminate called after throwing an instance of 'RtMidiError'
  what():  MidiInAlsa::initialize: error creating ALSA sequencer client object.
Aborted

I think what is happening is that while the ~NodeMidiInput() destructor deletes the RtMidiIn instance that it creates, I believe that there is no guarantee of when the destructor will get called by the garbage collector.

To test this theory, I've created a fork of node-midi that adds a function to explicitly delete the RtMidiIn instance:

master...simonbates:release-rtmidi

With this version, I'm able to create lots of midi.input() instances as long as I explicitly delete the associated RtMidiIn object when it's no longer needed:

var midi = require("midi");

for (var i = 0; i < 10000; i++) {
    var midiInput = new midi.input();
    midiInput.release();
}

process.exit();
simonbates added a commit to sbates-idrc/Flocking that referenced this issue Nov 18, 2016
On ALSA Linux, node-midi input and output objects hold onto resources that
eventually may run out causing the process to terminate. This change to
Flocking makes use of a work around added to a fork of node-midi which
adds a new explicit "release()" method to free the underlying RtMidi (and
corresponding ALSA) resources.

See: justinlatimer/node-midi#118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants