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

stdout/stderr buffering with TTY #2148

Closed
mscdex opened this issue Jul 9, 2015 · 15 comments
Closed

stdout/stderr buffering with TTY #2148

mscdex opened this issue Jul 9, 2015 · 15 comments
Labels
process Issues and PRs related to the process subsystem. repro-exists Issues with reproductions. tty Issues and PRs related to the tty subsystem.

Comments

@mscdex
Copy link
Contributor

mscdex commented Jul 9, 2015

Recently I discovered that at least with the latest io.js (currently testing with the next branch in particular) and possibly older versions, stdout and stderr seem to be buffering when those streams refer to a TTY.

Here's a simple example that replicates the issue for me:

while (true) {
  console.error('stderr is tty? ' + process.stderr.isTTY);
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  console.error('foo bar baz quux quuz aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc');
  require('fs').writeFileSync('/tmp/stderr_buffer_len', 'stderr buffer length=' + process.stderr._writableState.length + '\n');
}

In one terminal do tail -F /tmp/stderr_buffer_len and then in another do iojs test.js.

I also tested the same script with node v0.10.30 and the stderr buffer length is always 0.

@mscdex mscdex added the console Issues and PRs related to the console subsystem. label Jul 9, 2015
@mscdex
Copy link
Contributor Author

mscdex commented Jul 9, 2015

I just tested with node v0.12.6 and the same problem occurs, except I'm not able to interrupt/kill the process with ^C 😱

@brendanashworth
Copy link
Contributor

Is this related to #784?

@mscdex
Copy link
Contributor Author

mscdex commented Jul 9, 2015

@brendanashworth I'm not sure. I applied #1771 but that didn't affect things for some reason, however calling process.stderr._handle.setBlocking(true); manually before the loop does seem to fix it.

My guess is that it's because #1771 is explicitly checking for a stdout/stderr pipe (not TTY) and only setting blocking mode in that case.

@Fishrock123
Copy link
Contributor

@mscdex is the result of your test case that it fails to write all of it on interrupt?

@mscdex
Copy link
Contributor Author

mscdex commented Jul 20, 2015

@Fishrock123 When I used ^C and it worked, the process terminated immediately. It did not print anything more to the console after ^C. Is that what you mean?

@Fishrock123
Copy link
Contributor

I think this is indirectly a dupe of #784. I'd defer to #1771 (comment) and #1771 (comment)

Since we have no smoke testing we have no idea if my patch (or a modified patch) might break things terribly, and it is quite hacky, I'm currently punting on it indefinitely.

@Fishrock123 Fishrock123 added process Issues and PRs related to the process subsystem. and removed console Issues and PRs related to the console subsystem. labels Jul 22, 2015
@Fishrock123
Copy link
Contributor

Actually, there is a slight difference, I'm not sure why, but maybe this testcase doesn't catch it.

I think the first underlying write of chunked output should effectively be synchronous (it effectively is in the other issue's testcase), but I'm not sure why that doesn't show here.

@brendanashworth brendanashworth added the tty Issues and PRs related to the tty subsystem. label Aug 10, 2015
@Fishrock123
Copy link
Contributor

Apparently stdout/stderr should always be blocking anyways: https://iojs.org/api/process.html#process_process_stdout...

@ChALkeR
Copy link
Member

ChALkeR commented Aug 25, 2015

#1741 should be linked here.

orangejulius added a commit to pelias/fuzzy-tester that referenced this issue Dec 18, 2015
There seems to an [issue](nodejs/node#2148)
with some versions of Node that cause one of stderr and stdout to be
buffered, while the other is not. This jumbles output if both are used.
@Trott
Copy link
Member

Trott commented Mar 27, 2016

#5920 is a proposed known_issues test for this, for what that's worth.

Trott added a commit to Trott/io.js that referenced this issue Mar 28, 2016
Trott added a commit to Trott/io.js that referenced this issue Mar 31, 2016
PR-URL: nodejs#5920
Refs: nodejs#2148
Reviewed-By: Brian White <mscdex@mscdex.net>
@cjihrig cjihrig added the repro-exists Issues with reproductions. label Mar 31, 2016
evanlucas pushed a commit that referenced this issue Mar 31, 2016
PR-URL: #5920
Refs: #2148
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this issue Mar 31, 2016
PR-URL: #5920
Refs: #2148
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this issue Apr 11, 2016
PR-URL: #5920
Refs: #2148
Reviewed-By: Brian White <mscdex@mscdex.net>
@jasnell
Copy link
Member

jasnell commented May 1, 2017

@Fishrock123 @mscdex ... is this still an issue?

@mscdex
Copy link
Contributor Author

mscdex commented May 1, 2017

@jasnell I haven't tested specifically but since I believe writes to TTYs are now blocking on all platforms in master/v8.x, it should only be an issue on older versions (v7.x and older).

@jasnell
Copy link
Member

jasnell commented May 30, 2017

Given that we're not likely to change the defaults on the older versions for very good semver reasons, I'm inclined to close this. We can reopen if necessary

@jasnell jasnell closed this as completed May 30, 2017
@Trott
Copy link
Member

Trott commented Jul 10, 2017

Are we sure this is fixed? We have a known_issues test for it and it still fails.

@Trott Trott reopened this Jul 10, 2017
@Trott
Copy link
Member

Trott commented Sep 10, 2017

Actually, looks like I'm wrong and the test probably needs to be removed (or fixed). Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. repro-exists Issues with reproductions. tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants