Skip to content

Commit

Permalink
http: allow _httpMessage to be GC'ed
Browse files Browse the repository at this point in the history
Set `socket._httpMessage` to `null` before emitting the `'connect'` or
`'upgrade'` event.

PR-URL: #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>
  • Loading branch information
lpinca authored and MylesBorins committed Apr 13, 2018
1 parent d799b1c commit 1edadeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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);
}
Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-http-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ server.listen(0, common.mustCall(() => {
path: 'google.com:443'
}, common.mustNotCall());

req.on('close', common.mustCall(() => {}));
req.on('socket', common.mustCall((socket) => {
assert.strictEqual(socket._httpMessage, req);
}));

req.on('close', common.mustCall());

req.on('connect', common.mustCall((res, socket, firstBodyChunk) => {
// Make sure this request got removed from the pool.
Expand All @@ -39,6 +43,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);

Expand Down

0 comments on commit 1edadeb

Please sign in to comment.