forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
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: nodejs#28646 Refs: nodejs#29263 Fixes: nodejs#9668
- Loading branch information
Showing
3 changed files
with
66 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,42 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
const onGC = require('../common/ongc'); | ||
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() }); | ||
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(); | ||
})); |