1'use strict'; 2 3const common = require('../common'); 4const http = require('http'); 5const net = require('net'); 6 7const agent = new http.Agent({ 8 keepAlive: true, 9}); 10const socket = new net.Socket(); 11// If _handle exists then internals assume a couple methods exist. 12socket._handle = { 13 ref() { }, 14 readStart() { }, 15}; 16 17const server = http.createServer(common.mustCall((req, res) => { 18 res.end(); 19})).listen(0, common.mustCall(() => { 20 const req = new http.ClientRequest(`http://localhost:${server.address().port}/`); 21 22 // Manually add the socket without a _handle. 23 agent.freeSockets[agent.getName(req)] = [socket]; 24 // Now force the agent to use the socket and check that _handle exists before 25 // calling asyncReset(). 26 agent.addRequest(req, {}); 27 req.on('response', common.mustCall(() => { 28 server.close(); 29 })); 30 req.end(); 31})); 32