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);