2017-01-15 13:23:20 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
for (const destroyer of ['destroy', 'abort']) {
|
|
|
|
let socketsCreated = 0;
|
|
|
|
|
|
|
|
class Agent extends http.Agent {
|
|
|
|
createConnection(options, oncreate) {
|
|
|
|
const socket = super.createConnection(options, oncreate);
|
|
|
|
socketsCreated++;
|
|
|
|
return socket;
|
|
|
|
}
|
2017-01-15 13:23:20 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
const server = http.createServer((req, res) => res.end());
|
2017-01-15 13:23:20 +00:00
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const port = server.address().port;
|
|
|
|
const agent = new Agent({
|
|
|
|
keepAlive: true,
|
|
|
|
maxSockets: 1
|
|
|
|
});
|
2017-01-15 13:23:20 +00:00
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
http.get({ agent, port }, (res) => res.resume());
|
2017-01-15 13:23:20 +00:00
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
const req = http.get({ agent, port }, common.mustNotCall());
|
|
|
|
req[destroyer]();
|
2017-01-15 13:23:20 +00:00
|
|
|
|
2020-03-08 11:39:50 +00:00
|
|
|
if (destroyer === 'destroy') {
|
|
|
|
req.on('error', common.mustCall((err) => {
|
|
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
req.on('error', common.mustNotCall());
|
|
|
|
}
|
|
|
|
|
|
|
|
http.get({ agent, port }, common.mustCall((res) => {
|
|
|
|
res.resume();
|
|
|
|
assert.strictEqual(socketsCreated, 1);
|
|
|
|
agent.destroy();
|
|
|
|
server.close();
|
|
|
|
}));
|
2017-01-15 13:23:20 +00:00
|
|
|
}));
|
2020-03-08 11:39:50 +00:00
|
|
|
}
|