Skip to content

Commit

Permalink
fixup! http: handle cases where socket.server is null
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jun 10, 2017
1 parent 6f2e806 commit dd8e09a
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

// Regression test for https://github.com/nodejs/node/issues/13435
// Tests that `socket.server` is correctly set when a socket is sent to a worker
// and the `'connection'` event is emitted manually on an HTTP server.

const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
Expand All @@ -8,13 +12,11 @@ const net = require('net');

if (cluster.isMaster) {
const worker = cluster.fork();
const server = net.createServer({
pauseOnConnect: true
}, common.mustCall((socket) => {
const server = net.createServer(common.mustCall((socket) => {
worker.send('socket', socket);
}));

worker.on('exit', common.mustCall((code, signal) => {
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
server.close();
}));
Expand All @@ -25,13 +27,13 @@ if (cluster.isMaster) {
} else {
const server = http.createServer();

server.setTimeout(100, common.mustCall((socket) => {
server.on('connection', common.mustCall((socket) => {
assert.strictEqual(socket.server, server);
socket.destroy();
cluster.worker.kill();
cluster.worker.disconnect();
}));

process.on('message', common.mustCall((message, socket) => {
server.emit('connection', socket);
socket.resume();
}));
}

0 comments on commit dd8e09a

Please sign in to comment.