summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-08-02 02:50:31 +0200
committerJames M Snell <jasnell@gmail.com>2017-08-08 16:00:30 -0700
commit611851dabad3ab4f2f419f490b9b1f6818de7754 (patch)
tree01bd385f1f47ba397e7647c3048b3212ccb6eaa8 /test
parent9564c20810d7dccaae8bb917251681051a2a1144 (diff)
downloadandroid-node-v8-611851dabad3ab4f2f419f490b9b1f6818de7754.tar.gz
android-node-v8-611851dabad3ab4f2f419f490b9b1f6818de7754.tar.bz2
android-node-v8-611851dabad3ab4f2f419f490b9b1f6818de7754.zip
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: https://github.com/nodejs/node/pull/14588 Fixes: https://github.com/nodejs/node/issues/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>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-cluster-send-handle-large-payload.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-cluster-send-handle-large-payload.js b/test/parallel/test-cluster-send-handle-large-payload.js
new file mode 100644
index 0000000000..ba529593e2
--- /dev/null
+++ b/test/parallel/test-cluster-send-handle-large-payload.js
@@ -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();
+ }));
+}