-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: handle cases where socket.server is null
Fixes a regression that caused an error to be thrown when trying to emit the 'timeout' event on the server referenced by `socket.server`. Fixes: #13435 Refs: #11926 PR-URL: #13578 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
test/parallel/test-cluster-send-socket-to-worker-http-server.js
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,39 @@ | ||
'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'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
if (cluster.isMaster) { | ||
const worker = cluster.fork(); | ||
const server = net.createServer(common.mustCall((socket) => { | ||
worker.send('socket', socket); | ||
})); | ||
|
||
worker.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
server.close(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
net.createConnection(server.address().port); | ||
})); | ||
} else { | ||
const server = http.createServer(); | ||
|
||
server.on('connection', common.mustCall((socket) => { | ||
assert.strictEqual(socket.server, server); | ||
socket.destroy(); | ||
cluster.worker.disconnect(); | ||
})); | ||
|
||
process.on('message', common.mustCall((message, socket) => { | ||
server.emit('connection', socket); | ||
})); | ||
} |