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

process.stdout/.stderr might loose data when calling process.exit() #3669

Closed
minesworld opened this issue Nov 5, 2015 · 4 comments
Closed
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. process Issues and PRs related to the process subsystem.

Comments

@minesworld
Copy link

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.

@Fishrock123
Copy link
Contributor

Please see #3170 -- the docs are incorrect but the situation is complex.

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

@Fishrock123 Fishrock123 added duplicate Issues and PRs that are duplicates of other issues or PRs. process Issues and PRs related to the process subsystem. labels Nov 5, 2015
@Fishrock123
Copy link
Contributor

Please also see #2972 (comment)

(Oh dear, this again.)

@minesworld
Copy link
Author

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 ...

orangejulius added a commit to pelias/fuzzy-tester that referenced this issue Apr 4, 2016
`process.exit` quits immediately, without allowing buffered output from
say, a `console.log` to be printed. See these Node.js issues:

nodejs/node#3669
nodejs/node#3170
nodejs/node#2972 (comment)
@mikemaccana
Copy link
Contributor

See #6456 for the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants