11cb0ef41Sopenharmony_ci// Flags: --expose-gc
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst onGC = require('../common/ongc');
51cb0ef41Sopenharmony_ciconst { createServer } = require('http');
61cb0ef41Sopenharmony_ciconst { connect } = require('net');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Make sure that for HTTP keepalive requests, the req object can be
91cb0ef41Sopenharmony_ci// garbage collected once the request is finished.
101cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/9668
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cilet client;
131cb0ef41Sopenharmony_ciconst server = createServer(common.mustCall((req, res) => {
141cb0ef41Sopenharmony_ci  onGC(req, { ongc: common.mustCall(() => { server.close(); }) });
151cb0ef41Sopenharmony_ci  req.resume();
161cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
171cb0ef41Sopenharmony_ci    setImmediate(() => {
181cb0ef41Sopenharmony_ci      client.end();
191cb0ef41Sopenharmony_ci      global.gc();
201cb0ef41Sopenharmony_ci    });
211cb0ef41Sopenharmony_ci  }));
221cb0ef41Sopenharmony_ci  res.end('hello world');
231cb0ef41Sopenharmony_ci}));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
261cb0ef41Sopenharmony_ci  client = connect(server.address().port);
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  const req = [
291cb0ef41Sopenharmony_ci    'POST / HTTP/1.1',
301cb0ef41Sopenharmony_ci    `Host: localhost:${server.address().port}`,
311cb0ef41Sopenharmony_ci    'Connection: keep-alive',
321cb0ef41Sopenharmony_ci    'Content-Length: 11',
331cb0ef41Sopenharmony_ci    '',
341cb0ef41Sopenharmony_ci    'hello world',
351cb0ef41Sopenharmony_ci    '',
361cb0ef41Sopenharmony_ci  ].join('\r\n');
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  client.write(req);
391cb0ef41Sopenharmony_ci  client.unref();
401cb0ef41Sopenharmony_ci}));
41