From 29c395d9756b56d111f13c976112f54c4f4ed1e5 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 19 Feb 2018 14:43:02 +0100 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina --- lib/_http_agent.js | 1 + test/parallel/test-http-connect.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 5f1e56caeab981..7586a48680bb6a 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -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); } diff --git a/test/parallel/test-http-connect.js b/test/parallel/test-http-connect.js index b019c61573e3fa..0ec682d1b7a03d 100644 --- a/test/parallel/test-http-connect.js +++ b/test/parallel/test-http-connect.js @@ -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);