-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
net: make stdout & stderr block on all platforms #1771
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
net: make stdout & stderr block on all platforms
Previously, if a write to stdout (or stderr) was long enough that it
would have to be broken into chunks for writing, and the process was
terminated before all of those chunks were written, they would be lost.
This prevents chunks from being lost or delayed by making writes to
std{out|err} synchronous (and thus blocking).
Fixes: #784- Loading branch information
commit a99699665323061bfdd835842d3d202e502e48d5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 'use strict'; | ||
|
|
||
| // Produce a very long string, so that stdout will have to break it into chunks. | ||
| var str = 'test\n'; | ||
| for (var i = 0; i < 17; i++, str += str); | ||
|
|
||
| // Add something so that we can identify the end. | ||
| str += 'hey\n'; | ||
|
|
||
| process.stdout.write(str); | ||
|
|
||
| // Close the process, attempting to close before | ||
| // all chunked stdout writes are done. | ||
| // | ||
| // This is required to achieve the regression described in | ||
| // https://github.com/nodejs/io.js/issues/784. | ||
| process.exit(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const fork = require('child_process').fork; | ||
| const stream = require('stream'); | ||
| const path = require('path'); | ||
|
|
||
| const producer = fork(path.join(common.fixturesDir, 'stdout-producer.js'), | ||
| { silent: true }); | ||
|
|
||
| var output = ''; | ||
| const writable = new stream.Writable({ | ||
| write(chunk, _, next) { | ||
| output += chunk.toString(); | ||
| next(); | ||
| } | ||
| }); | ||
|
|
||
| producer.stdout.pipe(writable); | ||
| producer.stdout.on('close', function() { | ||
| assert(output.endsWith('hey\n'), | ||
| 'Not all chunked writes were completed before process termination.'); | ||
| }); | ||
|
|
||
| producer.stderr.pipe(process.stderr); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.exit()unconditionally terminates the process. Even when stdio is synchronous, there is no guarantee that the other end will have received it all.EDIT: It's probably a bad idea in general to call
process.exit()in tests, it tends to hide bugs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, however, I'm not able to produce the regression without it, what do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, can you add a comment explaining that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, though I'm not sure of the specifics. I could take a dive into it if need be.