-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: fix handle passing w large payloads
Fix situations in which the handle passed along with a message that has a large payload and can’t be read entirely by a single `recvmsg()` call isn’t associated with the message to which it belongs. PR-URL: #14588 Fixes: #13778 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
- Loading branch information
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
|
||
const payload = 'a'.repeat(800004); | ||
|
||
if (cluster.isMaster) { | ||
const server = net.createServer(); | ||
|
||
server.on('connection', common.mustCall((socket) => socket.unref())); | ||
|
||
const worker = cluster.fork(); | ||
worker.on('message', common.mustCall(({ payload: received }, handle) => { | ||
assert.strictEqual(payload, received); | ||
assert(handle instanceof net.Socket); | ||
server.close(); | ||
handle.destroy(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const socket = new net.Socket(); | ||
socket.connect(port, (err) => { | ||
assert.ifError(err); | ||
worker.send({ payload }, socket); | ||
}); | ||
})); | ||
} else { | ||
process.on('message', common.mustCall(({ payload: received }, handle) => { | ||
assert.strictEqual(payload, received); | ||
assert(handle instanceof net.Socket); | ||
process.send({ payload }, handle); | ||
|
||
// Prepare for a clean exit. | ||
process.channel.unref(); | ||
handle.unref(); | ||
})); | ||
} |