Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fff8a56

Browse filesBrowse files
lpincaaddaleax
authored andcommitted
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>
1 parent 38a1cfb commit fff8a56
Copy full SHA for fff8a56

File tree

Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed
Open diff view settings
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ function connectionListener(socket) {
291291

292292
httpSocketSetup(socket);
293293

294+
// Ensure that the server property of the socket is correctly set.
295+
// See https://github.com/nodejs/node/issues/13435
296+
if (socket.server === null)
297+
socket.server = this;
298+
294299
// If the user has added a listener to the server,
295300
// request, or response, then it's their responsibility.
296301
// otherwise, destroy on timeout by default
Collapse file
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
// Regression test for https://github.com/nodejs/node/issues/13435
4+
// Tests that `socket.server` is correctly set when a socket is sent to a worker
5+
// and the `'connection'` event is emitted manually on an HTTP server.
6+
7+
const common = require('../common');
8+
const assert = require('assert');
9+
const cluster = require('cluster');
10+
const http = require('http');
11+
const net = require('net');
12+
13+
if (cluster.isMaster) {
14+
const worker = cluster.fork();
15+
const server = net.createServer(common.mustCall((socket) => {
16+
worker.send('socket', socket);
17+
}));
18+
19+
worker.on('exit', common.mustCall((code) => {
20+
assert.strictEqual(code, 0);
21+
server.close();
22+
}));
23+
24+
server.listen(0, common.mustCall(() => {
25+
net.createConnection(server.address().port);
26+
}));
27+
} else {
28+
const server = http.createServer();
29+
30+
server.on('connection', common.mustCall((socket) => {
31+
assert.strictEqual(socket.server, server);
32+
socket.destroy();
33+
cluster.worker.disconnect();
34+
}));
35+
36+
process.on('message', common.mustCall((message, socket) => {
37+
server.emit('connection', socket);
38+
}));
39+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.