mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 02:32:39 +00:00

If an uninitialized or user supplied Socket is in the freeSockets list of the Agent it would automatically attempt to run ._handle.asyncReset(), but would throw from those not existing. Guard against that by first checking that they exist. PR-URL: https://github.com/nodejs/node/pull/14419 Fixes: https://github.com/nodejs/node/issues/13539 Refs: https://github.com/nodejs/node/issues/13352 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
31 lines
844 B
JavaScript
31 lines
844 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
|
|
const agent = new http.Agent({
|
|
keepAlive: true,
|
|
});
|
|
const socket = new net.Socket();
|
|
// If _handle exists then internals assume a couple methods exist.
|
|
socket._handle = {
|
|
ref() { },
|
|
readStart() { },
|
|
};
|
|
const req = new http.ClientRequest(`http://localhost:${common.PORT}/`);
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end();
|
|
})).listen(common.PORT, common.mustCall(() => {
|
|
// Manually add the socket without a _handle.
|
|
agent.freeSockets[agent.getName(req)] = [socket];
|
|
// Now force the agent to use the socket and check that _handle exists before
|
|
// calling asyncReset().
|
|
agent.addRequest(req, {});
|
|
req.on('response', common.mustCall(() => {
|
|
server.close();
|
|
}));
|
|
req.end();
|
|
}));
|