http: allow _httpMessage to be GC'ed

Set `socket._httpMessage` to `null` before emitting the `'connect'` or
`'upgrade'` event.

PR-URL: https://github.com/nodejs/node/pull/18865
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Luigi Pinca 2018-02-19 14:43:02 +01:00 committed by Ruben Bridgewater
parent 5055c29e82
commit e5369e054b
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 6 additions and 0 deletions

View File

@ -277,6 +277,7 @@ function installListeners(agent, s, options) {
s.removeListener('close', onClose);
s.removeListener('free', onFree);
s.removeListener('agentRemove', onRemove);
s._httpMessage = null;
}
s.on('agentRemove', onRemove);
}

View File

@ -49,6 +49,10 @@ server.listen(0, common.mustCall(() => {
path: 'google.com:443'
}, common.mustNotCall());
req.on('socket', common.mustCall((socket) => {
assert.strictEqual(socket._httpMessage, req);
}));
req.on('close', common.mustCall());
req.on('connect', common.mustCall((res, socket, firstBodyChunk) => {
@ -60,6 +64,7 @@ server.listen(0, common.mustCall(() => {
// Make sure this socket has detached.
assert(!socket.ondata);
assert(!socket.onend);
assert.strictEqual(socket._httpMessage, null);
assert.strictEqual(socket.listeners('connect').length, 0);
assert.strictEqual(socket.listeners('data').length, 0);