2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-07-27 13:36:35 +02:00
|
|
|
// Flags: --expose-gc
|
|
|
|
// just like test-gc-http-client.js,
|
2012-05-03 10:16:25 -07:00
|
|
|
// but aborting every connection that comes in.
|
|
|
|
|
2018-10-01 14:28:18 +03:00
|
|
|
const common = require('../common');
|
2024-08-13 18:28:21 +08:00
|
|
|
const { onGC } = require('../common/gc');
|
2016-05-08 23:04:17 -07:00
|
|
|
const http = require('http');
|
2022-04-19 15:36:57 +02:00
|
|
|
const os = require('os');
|
|
|
|
|
2022-12-29 10:38:04 +09:00
|
|
|
const cpus = os.availableParallelism();
|
2022-04-19 15:36:57 +02:00
|
|
|
let createClients = true;
|
2016-01-13 21:42:45 +01:00
|
|
|
let done = 0;
|
|
|
|
let count = 0;
|
|
|
|
let countGC = 0;
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2018-10-01 14:28:18 +03:00
|
|
|
function serverHandler(req, res) {
|
|
|
|
res.connection.destroy();
|
|
|
|
}
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(serverHandler);
|
2018-10-01 14:28:18 +03:00
|
|
|
server.listen(0, common.mustCall(() => {
|
2022-04-19 15:36:57 +02:00
|
|
|
for (let i = 0; i < cpus; i++)
|
|
|
|
getAll();
|
2018-10-01 14:28:18 +03:00
|
|
|
}));
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2022-04-19 15:36:57 +02:00
|
|
|
function getAll() {
|
|
|
|
if (!createClients)
|
2014-02-24 10:20:30 -08:00
|
|
|
return;
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2018-10-01 14:28:18 +03:00
|
|
|
const req = http.get({
|
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
|
|
|
port: server.address().port
|
|
|
|
}, cb).on('error', cb);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2018-10-01 14:28:18 +03:00
|
|
|
count++;
|
|
|
|
onGC(req, { ongc });
|
2014-02-24 10:20:30 -08:00
|
|
|
|
2022-04-19 15:36:57 +02:00
|
|
|
setImmediate(getAll);
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|
|
|
|
|
2018-10-01 14:28:18 +03:00
|
|
|
function cb(res) {
|
|
|
|
done += 1;
|
|
|
|
}
|
2014-02-24 10:20:30 -08:00
|
|
|
|
2018-07-27 13:36:35 +02:00
|
|
|
function ongc() {
|
2016-02-03 12:27:40 -08:00
|
|
|
countGC++;
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|
|
|
|
|
2022-04-19 15:36:57 +02:00
|
|
|
setImmediate(status);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
|
|
|
function status() {
|
2022-04-19 15:36:57 +02:00
|
|
|
if (done > 0) {
|
|
|
|
createClients = false;
|
2025-01-22 15:30:30 -08:00
|
|
|
globalThis.gc();
|
2022-04-19 15:36:57 +02:00
|
|
|
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
|
|
|
|
if (countGC === count) {
|
|
|
|
server.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setImmediate(status);
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|