-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: reset parser.incoming when server request is finished
This resolves a memory leak for keep-alive connections and does not regress in the way that 779a05d did by waiting for the incoming request to be finished before releasing the `parser.incoming` object. Refs: #28646 Refs: #29263 Fixes: #9668 PR-URL: #29297 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
3 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
const onGC = require('../common/ongc'); | ||
const { createServer } = require('http'); | ||
const { connect } = require('net'); | ||
|
||
if (common.isWindows) { | ||
// TODO(addaleax): Investigate why and remove the skip. | ||
common.skip('This test is flaky on Windows.'); | ||
} | ||
|
||
// 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() }); | ||
req.resume(); | ||
req.on('end', common.mustCall(() => { | ||
setImmediate(() => { | ||
client.end(); | ||
global.gc(); | ||
}); | ||
})); | ||
res.end('hello world'); | ||
})); | ||
|
||
server.unref(); | ||
|
||
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(); | ||
})); |