-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
http: reset parser.incoming when server request is finished #29297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
40a2a8e
http: reset parser.incoming when server request is finished
addaleax 5cd5402
fixup! http: reset parser.incoming when server request is finished
addaleax 6232470
fixup! http: reset parser.incoming when server request is finished
addaleax 18637be
fixup! http: reset parser.incoming when server request is finished
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
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
- Loading branch information
commit 40a2a8edc0943b7eb4b33b515d80803d2ef93e68
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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(); | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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(); | ||
| })); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.