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 12const server = http.createServer(common.mustCall((req, res) => { 13 res.end(); 14})).listen(0, common.mustCall(() => { 15 const req = new http.ClientRequest(`http://localhost:${server.address().port}/`); 16 17 // Manually add the socket without a _handle. 18 agent.freeSockets[agent.getName(req)] = [socket]; 19 // Now force the agent to use the socket and check that _handle exists before 20 // calling asyncReset(). 21 agent.addRequest(req, {}); 22 req.on('response', common.mustCall(() => { 23 server.close(); 24 })); 25 req.end(); 26})); 27