Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 1022c0c

Browse files
bnoordhuistrevnorris
authored andcommitted
lib: fix process.send() sync i/o regression
process.send() should be synchronous, i.e. it should block until the message has been sent in full, but it wasn't after the second-to-last libuv upgrade because of commit libuv/libuv@393c1c5 ("unix: set non-block mode in uv_{pipe,tcp,udp}_open"), which made its way into io.js in commit 07bd05b ("deps: update libuv to 1.2.1"). Commit libuv/libuv@b36d4ff ("unix: implement uv_stream_set_blocking()") as landed in io.js in commit 9681fca ("deps: update libuv to 1.4.0") makes it possible to restore the synchronous behavior again and that's precisely what this commit does. PR-URL: nodejs/node#774 Reviewed-by: Trevor Norris <[email protected]>
1 parent 41675fa commit 1022c0c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/child_process.js

+7
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,13 @@ exports._forkChild = function(fd) {
586586
// set process.send()
587587
var p = createPipe(true);
588588
p.open(fd);
589+
590+
// p.open() puts the file descriptor in non-blocking mode
591+
// but it must be synchronous for backwards compatibility.
592+
var err = p.setBlocking(true);
593+
if (err)
594+
throw errnoException(err, 'setBlocking');
595+
589596
p.unref();
590597
setupChannel(process, p);
591598

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
var assert = require('assert');
24+
var fork = require('child_process').fork;
25+
var N = 4 << 20; // 4 MB
26+
27+
for (var big = '*'; big.length < N; big += big);
28+
29+
if (process.argv[2] === 'child') {
30+
process.send(big);
31+
process.exit(42);
32+
}
33+
34+
var proc = fork(__filename, ['child']);
35+
36+
proc.on('message', common.mustCall(function(msg) {
37+
assert.equal(typeof msg, 'string');
38+
assert.equal(msg.length, N);
39+
assert.equal(msg, big);
40+
}));
41+
42+
proc.on('exit', common.mustCall(function(exitCode) {
43+
assert.equal(exitCode, 42);
44+
}));

0 commit comments

Comments
 (0)