diff --git a/lib/_http_server.js b/lib/_http_server.js index 357400e3501228..6d5dbf4584a7ef 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -294,6 +294,11 @@ function connectionListener(socket) { httpSocketSetup(socket); + // Ensure that the server property of the socket is correctly set. + // See https://github.com/nodejs/node/issues/13435 + if (socket.server === null) + socket.server = this; + // If the user has added a listener to the server, // request, or response, then it's their responsibility. // otherwise, destroy on timeout by default diff --git a/test/parallel/test-regress-GH-13435.js b/test/parallel/test-regress-GH-13435.js new file mode 100644 index 00000000000000..28f00552092f8b --- /dev/null +++ b/test/parallel/test-regress-GH-13435.js @@ -0,0 +1,37 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const http = require('http'); +const net = require('net'); + +if (cluster.isMaster) { + const worker = cluster.fork(); + const server = net.createServer({ + pauseOnConnect: true + }, common.mustCall((socket) => { + worker.send('socket', socket); + })); + + worker.on('exit', common.mustCall((code, signal) => { + assert.strictEqual(code, 0); + server.close(); + })); + + server.listen(0, common.mustCall(() => { + net.createConnection(server.address().port); + })); +} else { + const server = http.createServer(); + + server.setTimeout(100, common.mustCall((socket) => { + socket.destroy(); + cluster.worker.kill(); + })); + + process.on('message', common.mustCall((message, socket) => { + server.emit('connection', socket); + socket.resume(); + })); +}