2019-08-24 20:42:11 +02:00
|
|
|
// Flags: --expose-gc
|
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2024-08-13 18:28:21 +08:00
|
|
|
const { onGC } = require('../common/gc');
|
2019-08-24 20:42:11 +02:00
|
|
|
const { createServer } = require('http');
|
|
|
|
const { connect } = require('net');
|
|
|
|
|
|
|
|
// Make sure that for HTTP keepalive requests, the req object can be
|
|
|
|
// garbage collected once the request is finished.
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/9668
|
|
|
|
|
|
|
|
let client;
|
|
|
|
const server = createServer(common.mustCall((req, res) => {
|
2019-08-27 14:55:40 -07:00
|
|
|
onGC(req, { ongc: common.mustCall(() => { server.close(); }) });
|
2019-08-24 20:42:11 +02:00
|
|
|
req.resume();
|
|
|
|
req.on('end', common.mustCall(() => {
|
2024-05-28 21:47:19 +00:00
|
|
|
setImmediate(async () => {
|
2019-08-24 20:42:11 +02:00
|
|
|
client.end();
|
2025-01-22 15:30:30 -08:00
|
|
|
await globalThis.gc({ type: 'major', execution: 'async' });
|
|
|
|
await globalThis.gc({ type: 'major', execution: 'async' });
|
2019-08-24 20:42:11 +02:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
res.end('hello world');
|
|
|
|
}));
|
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
client = connect(server.address().port);
|
|
|
|
|
|
|
|
const req = [
|
|
|
|
'POST / HTTP/1.1',
|
|
|
|
`Host: localhost:${server.address().port}`,
|
|
|
|
'Connection: keep-alive',
|
|
|
|
'Content-Length: 11',
|
|
|
|
'',
|
|
|
|
'hello world',
|
2021-03-26 08:51:08 -07:00
|
|
|
'',
|
2019-08-24 20:42:11 +02:00
|
|
|
].join('\r\n');
|
|
|
|
|
|
|
|
client.write(req);
|
|
|
|
client.unref();
|
|
|
|
}));
|