diff --git a/lib/_http_agent.js b/lib/_http_agent.js index f11fa9fd6d2f5f..ce4cd05005e211 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -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); } diff --git a/test/parallel/test-http-connect.js b/test/parallel/test-http-connect.js index 854d2d893416a0..9854c68be98ce2 100644 --- a/test/parallel/test-http-connect.js +++ b/test/parallel/test-http-connect.js @@ -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. @@ -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);