Node: process.stdout/.stderr might loose data when calling process.exit()

Created on 5 Nov 2015  路  4Comments  路  Source: nodejs/node

this won't work reliable (but it should according to the docs):

  var empty = new Buffer(0)
  process.stdout.write(empty, function() { 
    process.stderr.write(empty, function() { 
       process.exit(code);
    });
  });

Not all data is flushed when node.js ends and thus another process using its output will not get all written data.

It also doesn't help to use something like

stream.pipe(process.stdout);
stream.push(null);

That .end() throws and an finish is never emitted makes using process.stdout/.stderr something like lottery.

Also trying to workaround via

fs.createWritableStream(null, {fd:1});

leads to another bunch of problems like EAGAIN errors.

I would suggest to implement .end() and finish events so that both process.stdout and .stderr behave like any other stream.

duplicate process

Most helpful comment

Yes, this again. And shame on me that I thought node.js could be used to write a unix like tool without looking on the CLOSED issues. The "issue" thing here works as reliable as process.stdout/.stderr ...

All 4 comments

Please see https://github.com/nodejs/node/pull/3170 -- the docs are incorrect but the situation is complex.

I recommend you avoid using process.exit() whenever possible.

Please also see https://github.com/nodejs/node/issues/2972#issuecomment-146078649

(Oh dear, this again.)

Yes, this again. And shame on me that I thought node.js could be used to write a unix like tool without looking on the CLOSED issues. The "issue" thing here works as reliable as process.stdout/.stderr ...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

akdor1154 picture akdor1154  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

seishun picture seishun  路  3Comments