mirror of https://github.com/lukechilds/node.git
Browse Source
There's an issue on some `OS X` versions when passing fd's between processes. When the handle associated to a specific file descriptor is closed by the sender process before it's received in the destination, the handle is indeed closed while it should remain opened. In order to fix this behaviour, don't close the handle until the `NODE_HANDLE_ACK` is received by the sender. Added `test-child-process-pass-fd` that is basically `test-cluster-net-send` but creating lots of workers, so the issue reproduces on `OS X` consistently. Fixes: https://github.com/nodejs/node/issues/7512 PR-URL: https://github.com/nodejs/node/pull/7572 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>v7.x
Santiago Gimeno
9 years ago
2 changed files with 86 additions and 8 deletions
@ -0,0 +1,53 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const fork = require('child_process').fork; |
|||
const net = require('net'); |
|||
|
|||
if ((process.config.variables.arm_version === '6') || |
|||
(process.config.variables.arm_version === '7')) { |
|||
common.skip('Too slow for armv6 and armv7 bots'); |
|||
return; |
|||
} |
|||
|
|||
const N = 80; |
|||
|
|||
if (process.argv[2] !== 'child') { |
|||
for (let i = 0; i < N; ++i) { |
|||
const worker = fork(__filename, ['child', common.PORT + i]); |
|||
worker.once('message', common.mustCall((msg, handle) => { |
|||
assert.strictEqual(msg, 'handle'); |
|||
assert.ok(handle); |
|||
worker.send('got'); |
|||
|
|||
let recvData = ''; |
|||
handle.on('data', common.mustCall((data) => { |
|||
recvData += data; |
|||
})); |
|||
|
|||
handle.on('end', () => { |
|||
assert.strictEqual(recvData, 'hello'); |
|||
worker.kill(); |
|||
}); |
|||
})); |
|||
} |
|||
} else { |
|||
let socket; |
|||
const port = process.argv[3]; |
|||
let cbcalls = 0; |
|||
function socketConnected() { |
|||
if (++cbcalls === 2) |
|||
process.send('handle', socket); |
|||
} |
|||
|
|||
const server = net.createServer((c) => { |
|||
process.once('message', function(msg) { |
|||
assert.strictEqual(msg, 'got'); |
|||
c.end('hello'); |
|||
}); |
|||
socketConnected(); |
|||
}); |
|||
server.listen(port, common.localhostIPv4, () => { |
|||
socket = net.connect(port, common.localhostIPv4, socketConnected); |
|||
}); |
|||
} |
Loading…
Reference in new issue