Skip to content

Commit

Permalink
net: make stdout & stderr block on all platforms
Browse files Browse the repository at this point in the history
Fixes: nodejs#784
  • Loading branch information
Fishrock123 committed May 25, 2015
1 parent 2bb2f06 commit 1602b9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ function Socket(options) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
if ((options.fd == 1 || options.fd == 2) &&
(this._handle instanceof Pipe) &&
process.platform === 'win32') {
// Make stdout and stderr blocking on Windows
this._handle instanceof Pipe) {
var err = this._handle.setBlocking(true);
if (err)
throw errnoException(err, 'setBlocking');
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/stdout-producer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const add = 'test\n';

var str = '';
for (var i = 0; i < 100000; i++) {
str += add;
}

str += 'hey\n';

process.stdout.write(str);
process.exit();
27 changes: 27 additions & 0 deletions test/parallel/test-child-process-chunked-stdout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'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 found = '';
const writable = new stream.Writable({
write (chunk, _, next) {
const lines = chunk.toString().split('\n');

found = lines[lines.length - 2];
next();
}
})

producer.stdout.pipe(writable);
producer.stdout.on('close', function() {
assert.strictEqual(found, 'hey');
})

producer.stderr.pipe(process.stderr);

0 comments on commit 1602b9b

Please sign in to comment.