mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
0b6b2a4dc7
PR-URL: https://github.com/nodejs/node/pull/54355 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Flags: --expose-gc
|
|
'use strict';
|
|
const common = require('../common');
|
|
const { onGC } = require('../common/gc');
|
|
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) => {
|
|
onGC(req, { ongc: common.mustCall(() => { server.close(); }) });
|
|
req.resume();
|
|
req.on('end', common.mustCall(() => {
|
|
setImmediate(async () => {
|
|
client.end();
|
|
await global.gc({ type: 'major', execution: 'async' });
|
|
await global.gc({ type: 'major', execution: 'async' });
|
|
});
|
|
}));
|
|
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',
|
|
'',
|
|
].join('\r\n');
|
|
|
|
client.write(req);
|
|
client.unref();
|
|
}));
|