-
Notifications
You must be signed in to change notification settings - Fork 30k
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
errors and contradictions in docs for process.stdout/stderr #10617
Comments
/wall of text comment/ I suppose I am best qualified to answer this. First off, please look at https://nodejs.org/dist/latest-v7.x/docs/api/process.html#process_process_stdout rather than the Reading more... |
I suppose it could be clarified. Here is a summary to the best of my (confident) understanding:
I'm not sure where you got this from but that is an older version of the UNIX comment. Also, TTYs definitely do not block on Windows.
It may not be your understanding but it would be prudent to check the history. There is various information linked to from this issue: #6980. Also to reiterate: Non-windows platforms block when interacting with TTYs by default. They do not block to Pipes. Windows is the opposite. Edit: Is the behaviour confusing? Yes. Is there a better answer? ¯\_(ツ)_/¯ |
@Fishrock123 re:
Thanks for the historical references. I found via #6980 the PR #6895, and can see that you authored this text. From what I can see, it was accurate at the time you added it. It must have been some time after that, when TTYs became blocking on all UNIX systems, that your original text was not updated and thus became retroactively confusing, but my goal is to improve the current accuracy of the docs, not explore the history of how we got here. I take it that you are suggesting that the OS X 1K buffer size, the interleaving of I/O, and the truncation of output on process.exit (which is mentioned repeatedly in #6980) be included in the docs to justify their unique sync nature on UNIXes? Isn't the 1K buffer size just something that made the output truncation and interleaving more common on OS X than Linux, rather than a sufficient reason in itself to make TTYs synchronous? I quoted:
You said:
I preceeded every set of quotes with a link to its source, that one is from https://github.com/nodejs/node/blob/master/doc/api/process.md#tty-terminals-and-processstdout and is current. Or do you mean older as-in, it preceeded the changes and didn't get updated when it should have?
... and UNIX Pipes are blocking (to confirm). OK, with that info and your other confirmations I should be able to correct the docs, thanks. |
Pipes are non-blocking by default except on Windows.
Oh I understand now, yes, sorry. It should probably clarified that this is mostly a workaround for OS X but other platforms are also adjusted because the difference in negligible otherwise and maintains better consistency. |
It was the primary reason, but similar problems exist on all platforms above their buffer size. |
Ignore me, I missed the context here. |
process.stdout, process.stderr, and console.log() and console.error() which use the process streams, are usually synchronous. Warn about this, and clearly describe the conditions under which they are synchronous. Fix: nodejs#10617 PR-URL: nodejs#10884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process.stdout, process.stderr, and console.log() and console.error() which use the process streams, are usually synchronous. Warn about this, and clearly describe the conditions under which they are synchronous. Fix: nodejs#10617 PR-URL: nodejs#10884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process.stdout, process.stderr, and console.log() and console.error() which use the process streams, are usually synchronous. Warn about this, and clearly describe the conditions under which they are synchronous. Fix: #10617 PR-URL: #10884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process.stdout, process.stderr, and console.log() and console.error() which use the process streams, are usually synchronous. Warn about this, and clearly describe the conditions under which they are synchronous. Fix: #10617 PR-URL: #10884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process.stdout, process.stderr, and console.log() and console.error() which use the process streams, are usually synchronous. Warn about this, and clearly describe the conditions under which they are synchronous. Fix: #10617 PR-URL: #10884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This situation keeps changing around, but my understanding ATM is that process.stdout and process.stderr (fd 1 and 2) are set blocking when they are files, and on UNIX (OS X/Linux) also set blocking when they are TTYs. I'm not sure what is done if they are pipes or any of the other possible UNIX devices.
I think the standard way to describe this in node documentaion is that an API that "can block" is synchronous (it runs to completion, whether the OS blocks or not will depend on buffering, etc, but its the run-to-completion that is important), and to describe "non-blocking" APIs the word "asynchronous" is used.
Given that understanding, the docs have these problems:
In https://github.com/nodejs/node/blob/master/doc/api/process.md#processstderr
Should say that stdout/err is synchronous when connected to a file. I believe that use of the word "can" is trying to express that blocking won't occur unless the O/S chooses to block, but its not very helpful. It could also mean "node reserves the right to set the fd to blocking mode, or not to, so depend on nothing", but I don't think it means that.
Probably meant to be a note about previous statement, but because of list structure, reads as a note on the
i.
andii.
bullet points that follow.If we wanted to, we could say "If data is written faster than the OS I/O systems can buffer it, blocking may occur, but that blocking is unusual even when process.stderr is synchronous due to modern OS I/O buffering strategies.".
Should say its sync. Whether it blocks or not depends on whether TTY buffers fill up. The file case used the weasel-word "can", but here we use the emphatic
WILL
, which is a contradictory, and its not true that writes to a TTY will block, even if the fd is set to blocking.Here its partially restating the "can block on files" from the earlier paragraph, except that the "can" is omitted. So, its a contradictory restating of previous docs. Should just say TTY writes are async on windows for historical reasons.
Nowhere in here does it say what happens when stdout/stderr is a pipe! An important case. Is it sync like files and TTYs? Async like TTY on Windows? Depends on system? I don't know, and the docs don't say.
Has a typo, a trailing
:
.isTTY
does not have to have same value for stdin/out/err. This sentence should say "stderr is attached to a TTY if theisTTY
property is set.", and should say nothing about stdin/stdout, leave that to their docs.In https://github.com/nodejs/node/blob/master/doc/api/process.md#processstdout
Copy and paste of the stderr docs, all comments apply to it.
In https://github.com/nodejs/node/blob/master/doc/api/process.md#tty-terminals-and-processstdout
Wrongly named, should be "TTY Terminals and process.stdout and process.stderr" or "TTY Terminals and process output".
Legally speaking, not wrong, since OS X is considered UNIX, and the above is true for UNIX, but is very misleading, since it implies they are not blocking for Windows and Linux (which is not true).
Should say stderr/out are synchronous when writing to TTYs on UNIX, to agree with previous docs.
Not my understanding, don't know where that crept in. Its sync because users expect
console.log('hello'); process.exit(0)
to not exit until the I/O has been written, so the I/O has to be sync, not async. :-(https://github.com/nodejs/node/blob/master/doc/api/console.md#asynchronous-vs-synchronous-consoles
That directly contradicts the docs for process.stdout and process.stderr, unless by usually "on windows" is meant, and "on OS X and Linux" is considered "unusual", but I think its just a misstatement.
Copied verbatim from https://github.com/nodejs/node/blob/master/doc/api/process.md#tty-terminals-and-processstdout, including with the problems.
Entire section should be replaced by a web link to https://github.com/nodejs/node/blob/master/doc/api/process.md#tty-terminals-and-processstdout
I'll PR improvements to this text after my understanding of how it currently works is confirmed.
The text was updated successfully, but these errors were encountered: