-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
stdout/stderr buffering considerationsΒ #6379
Copy link
Copy link
Closed as not planned
Labels
libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.netIssues and PRs related to the net subsystem.Issues and PRs related to the net subsystem.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.stdioIssues and PRs related to stdio.Issues and PRs related to stdio.
Metadata
Metadata
Assignees
Labels
libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.netIssues and PRs related to the net subsystem.Issues and PRs related to the net subsystem.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.stdioIssues and PRs related to stdio.Issues and PRs related to stdio.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried to discuss this some time ago at IRC, but postponed it for quite a long time. Also I started the discussion of this in #1741, but I would like to extract the more specific discussion to a separate issue.
I could miss some details, but will try to give a quick overview here.
Several issues here:
console.log(e.g. calling it in a loop) could chew up all the memory and die β Why does node/io.js hang when printing to the console inside a loop?Β #1741, Silly program or memory leak?Β #2970,Β Strange memory leaksΒ #3171, memory leaks of console.logΒ #18013.console.loghas different behavior while printing to a terminal and being redirected to a file. β Why does node/io.js hang when printing to the console inside a loop?Β #1741 (comment).As I understand it β the output has an implicit write buffer (as it's non-blocking) of unlimited size.
One approach to fixing this would be to:
For almost all cases, except for the ones that are currently broken, this would behave as a non-blocking buffer (because writes to the buffer are considerably faster than writes from the buffer to file/terminal).
For cases when the data is being piped to the output too quickly and when the output file/terminal does not manage to output it at the same rate β the write would turn into a blocking operation. It would also be blocking at the exit until all the data is written.
Another approach would be to monitor (and limit) the size of data that is contained in the implicit buffer coming from the async queue, and make the operations block when that limit is reached.