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 <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
lpinca authored and addaleax committed Feb 26, 2018
1 parent 16ef386 commit c7f9608
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-http-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);

Expand Down

0 comments on commit c7f9608

Please sign in to comment.