question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crashing with assertion/segmentation fault/bus error

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:31 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
ryanlawscommented, Aug 20, 2016

@grav Here’s an example, hacked down a bit so it only depends on node-midi, child_process, and segfault-handler.

midispawn.js

const cp = require('child_process');
const exitEvents = ['close', 'disconnect', 'error', 'exit'];

let inPortNumber = 1, outPortNumber = 1;
let outProcess = mountOutput(outPortNumber);
let inProcess = mountInput(inPortNumber, outProcess);

function mountInput(portNumber, outProcess) {
  let inProcess = cp.fork('./midiinchild.js', [portNumber]);

  inProcess.on('message', (m) => {
    m.thing = 'inProcess';
    outProcess.send(m);
  });

  exitEvents.forEach((eventType) => {
    inProcess.on(eventType, () => {
      console.log("inProcess sent (" + eventType + ")");
      outProcess.send({ method: 'crash', thing: 'inProcess' });
      mountInput(portNumber, outProcess);
    });
  });

  return inProcess;
}

function mountOutput(portNumber) {
  let outProcess = cp.fork('./midioutchild.js', [portNumber]);

  exitEvents.forEach((eventType) => {
    outProcess.on(eventType, () => {
      console.log("outProcess sent (" + eventType + ")");
      process.exit();
    });
  });

  return outProcess;
}

midiinchild.js

const midi = require('midi'), midiInput = new midi.input();
const SegfaultHandler = require('segfault-handler');

midiInput.on('message', (dt, msg) => {
  process.send({ method: 'midi', bytes: msg });
});

midiInput.openPort(Number.parseInt(process.argv[2], 10));

process.send({ method: 'ready' });

SegfaultHandler.registerHandler('incrash.log', (signal, address, stack) => {
  console.log({ signal, address, stack });
});

midioutchild.js

const midi = require('midi'), midiOutput = new midi.output();
const SegfaultHandler = require('segfault-handler');

let crashedThing = null;

midiOutput.openPort(Number.parseInt(process.argv[2], 10));

process.on('message', (m) => {
  if (m.method === 'crash' && !crashedThing) {
    crashedThing = m.thing;
    console.log(crashedThing + " crashed!");
    return;
  }

  if (m.method === 'ready' && m.thing === crashedThing) {
    console.log(crashedThing + "is back online!");
    crashedThing = null;
    return;
  }

  if (m.method === 'midi') {
    console.log("Received MIDI from input. Data: " + m.bytes.join(','));
    midiOutput.sendMessage(m.bytes);
  }
});

SegfaultHandler.registerHandler('outcrash.log', function(signal, address, stack) {
  console.log({signal, address, stack});
});
1reaction
justinlatimercommented, Jul 29, 2019

Happy days. Reopen if it comes back!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found