{"action":"opened","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/6879","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/6879/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/6879/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/6879/events","html_url":"https://github.com/nodejs/node/issues/6879","id":155769366,"number":6879,"title":"Question about sockets & http.request","user":{"login":"Avcajaraville","id":2271201,"avatar_url":"https://avatars.githubusercontent.com/u/2271201?v=3","gravatar_id":"","url":"https://api.github.com/users/Avcajaraville","html_url":"https://github.com/Avcajaraville","followers_url":"https://api.github.com/users/Avcajaraville/followers","following_url":"https://api.github.com/users/Avcajaraville/following{/other_user}","gists_url":"https://api.github.com/users/Avcajaraville/gists{/gist_id}","starred_url":"https://api.github.com/users/Avcajaraville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Avcajaraville/subscriptions","organizations_url":"https://api.github.com/users/Avcajaraville/orgs","repos_url":"https://api.github.com/users/Avcajaraville/repos","events_url":"https://api.github.com/users/Avcajaraville/events{/privacy}","received_events_url":"https://api.github.com/users/Avcajaraville/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-19T15:42:25Z","updated_at":"2016-05-19T15:42:25Z","closed_at":null,"body":"\r\n\r\n0\r\ndown vote\r\nfavorite\r\nIm writing some integration tests for a node project.\r\n\r\nWe need to get reliable metrics about server performance. For that, we want to open a socket between the server and the client before any test is performance, this way, we can eliminate the time needed to create a socket between client and server.\r\n\r\nI have created a small test case like this:\r\n````js\r\n'use strict';\r\n\r\nvar express = require( 'express' ),\r\n    net     = require('net'),\r\n    http    = require('http');\r\n\r\nvar host    = 'localhost',\r\n    port    = 8000;\r\n\r\ndescribe( 'dummy describe', function() {\r\n  var app, server, agent, opts;\r\n  before( function( done ) {\r\n    app = express();\r\n    app.get( '/', function( req, res, next ) {\r\n      res.send( 'stuff' );\r\n    });\r\n    server = http.createServer( app );\r\n    server.listen( 8000 );\r\n    agent = new http.Agent({ maxSockets: 1 });\r\n    agent.createConnection({ port: port, host: host }, function() {\r\n      return net.createConnection({ port: port, host: host }, function() {\r\n        console.log( 'Socket fd open on before block: ' + this._handle.fd );\r\n        done();\r\n      });\r\n    });\r\n    opts = {\r\n      hostname: host,\r\n      port: port,\r\n      path: '/',\r\n      agent: agent,\r\n      method: 'GET',\r\n    };\r\n  });\r\n  it( 'dummy test', function ( done ) {\r\n    var req = http.request( opts, function( res ) {\r\n      console.log( 'Socket fd used on GET: ' + res.socket._handle.fd );\r\n      done();\r\n    });\r\n    req.end();\r\n  });\r\n}); \r\n````\r\nHere, I can see the execution of the before block, where I console.log the socket file descriptor.\r\n\r\nReading node documentation, I figured out that his was the right way to pass a socket to a agent. But its not working, its output different sockets.\r\n\r\nI tried a thousands combinations, but got no luck.\r\n\r\nI want to manually connect to a socket, and then use it to perform http.request without having to re open a different socket.\r\n\r\nWhat would be the correct way of doing this ?"}}