mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 07:19:19 +00:00

This resolves a memory leak for keep-alive connections and does not
regress in the way that 779a05d5d1
did by waiting for
the incoming request to be finished before releasing the
`parser.incoming` object.
Refs: https://github.com/nodejs/node/pull/28646
Refs: https://github.com/nodejs/node/pull/29263
Fixes: https://github.com/nodejs/node/issues/9668
PR-URL: https://github.com/nodejs/node/pull/29297
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
39 lines
1000 B
JavaScript
39 lines
1000 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { createServer } = require('http');
|
|
const { connect } = require('net');
|
|
|
|
// Make sure that for HTTP keepalive requests, the .on('end') event is emitted
|
|
// on the incoming request object, and that the parser instance does not hold
|
|
// on to that request object afterwards.
|
|
|
|
const server = createServer(common.mustCall((req, res) => {
|
|
req.on('end', common.mustCall(() => {
|
|
const parser = req.socket.parser;
|
|
assert.strictEqual(parser.incoming, req);
|
|
process.nextTick(() => {
|
|
assert.strictEqual(parser.incoming, null);
|
|
});
|
|
}));
|
|
res.end('hello world');
|
|
}));
|
|
|
|
server.unref();
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const 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.end(req);
|
|
}));
|