cargomedia / cm-janus

UNMAINTAINED. cm/janus bridge
MIT License
2 stars 6 forks source link

Cannot write to buffer - blocks process from running #206

Closed tomaszdurka closed 8 years ago

tomaszdurka commented 8 years ago

As investigated: looks like lame is exhausting node.js' STDERR buffer?

$ strace -p 12542
Process 12542 attached - interrupt to quit
write(2, "\33[A\33[A\33[A", 9
vogdb commented 8 years ago

The problem is narrowed down. Currently we do

require('child-process-promise').spawn(command, commandArgs, {cwd: dir, capture: ['stdout']})

and this hangs the process. In the end it is killed by timeout. But if we add 'stderr' to 'capture':

require('child-process-promise').spawn(command, commandArgs, {cwd: dir, capture: ['stdout', 'stderr']})

then works fine. I guess it is a problem of the used thirdparty child-process-promise. Should I prepare a quick fix with stderr or dig deeper to the root?

vogdb commented 8 years ago

Ok. My previous suggestion is actually a proper solution. See more here http://stackoverflow.com/questions/20792427/why-is-my-node-child-process-that-i-created-via-spawn-hanging. Preparing a PR.

vogdb commented 8 years ago

@tomaszdurka please review

tomaszdurka commented 8 years ago

Ok. Quick question, did you actually reproduced it? As I am not sure :)

vogdb commented 8 years ago

Yep. Here is my playground. You can reverify.

var fs = require('fs');
var path = require('path');
var spawn = require('./child-process-promise').spawn;
var Promise = require('bluebird');
var rimraf = require('rimraf');

var command;
//var commandText = 'sleep 5';
var commandText = 'echo hello';
//var commandText = 'echo foo 1>&2';
//var commandText = 'lame ./delete/sample.wav ./delete/sample.mp3';
var commandArgs = [];
if (commandText.indexOf(' ') >= 0) {
  var commandParts = commandText.split(' ');
  command = commandParts.shift();
  commandArgs = commandParts;
}

var options = {
  cwd: __dirname,
  capture: ['stdout']
};

return spawn(command, commandArgs, options)
  .progress(function(childProcess) {
/*
    console.log('[spawn] childProcess.pid: ', childProcess.pid);
    childProcess.stdout.on('data', function(data) {
      console.log('[spawn] stdout: ', data.toString());
    });
*/
    //childProcess.stderr.on('data', function(data) {
    //  console.log('[spawn] stderr: ', data.toString());
    //});
  })
  .then(function(result) {
    //console.log('done', result.stdout.toString);
    return result.stdout.toString();
  })
  .fail(function(err) {
    console.error('ERROR: ', err);
  })
  //.catch(function(err) {
  //  console.error('ERROR: ', err);
  //});
vogdb commented 8 years ago

I can send to you the sample.wav but it breaks on simple echo too.

tomaszdurka commented 8 years ago

lgtm