Skip to content

Commit aaa649e

Browse files
committed
net: make stdout & stderr block on all platforms
Fixes: #784
1 parent 2bb2f06 commit aaa649e

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

lib/net.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ function Socket(options) {
125125
this._handle = createHandle(options.fd);
126126
this._handle.open(options.fd);
127127
if ((options.fd == 1 || options.fd == 2) &&
128-
(this._handle instanceof Pipe) &&
129-
process.platform === 'win32') {
130-
// Make stdout and stderr blocking on Windows
128+
this._handle instanceof Pipe) {
131129
var err = this._handle.setBlocking(true);
132130
if (err)
133131
throw errnoException(err, 'setBlocking');

test/fixtures/stdout-producer.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const add = 'test\n';
4+
5+
var str = '';
6+
for (var i = 0; i < 1e5; i++) {
7+
str += add;
8+
}
9+
10+
str += 'hey\n';
11+
12+
process.stdout.write(str);
13+
process.exit();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const fork = require('child_process').fork;
6+
const stream = require('stream');
7+
const path = require('path');
8+
9+
const producer = fork(path.join(common.fixturesDir, 'stdout-producer.js'),
10+
{ silent: true });
11+
12+
var found = '';
13+
const writable = new stream.Writable({
14+
write(chunk, _, next) {
15+
const lines = chunk.toString().split('\n');
16+
17+
found = lines[lines.length - 2];
18+
next();
19+
}
20+
});
21+
22+
producer.stdout.pipe(writable);
23+
producer.stdout.on('close', function() {
24+
assert.strictEqual(found, 'hey');
25+
});
26+
27+
producer.stderr.pipe(process.stderr);

0 commit comments

Comments
 (0)