-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fixes memory retention issue with FreeList and HTTPParser
Fixes: #29394 Refs: #33167 (comment) PR-URL: #33190 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const { HTTPParser } = require('_http_common'); | ||
|
||
// Test that the `HTTPParser` instance is cleaned up before being returned to | ||
// the pool to avoid memory retention issues. | ||
|
||
const kOnTimeout = HTTPParser.kOnTimeout | 0; | ||
const server = http.createServer(); | ||
|
||
server.on('request', common.mustCall((request, response) => { | ||
const parser = request.socket.parser; | ||
|
||
assert.strictEqual(typeof parser[kOnTimeout], 'function'); | ||
|
||
request.socket.on('close', common.mustCall(() => { | ||
assert.strictEqual(parser[kOnTimeout], null); | ||
})); | ||
|
||
response.end(); | ||
server.close(); | ||
})); | ||
|
||
server.listen(common.mustCall(() => { | ||
const request = http.get({ port: server.address().port }); | ||
let parser; | ||
|
||
request.on('socket', common.mustCall(() => { | ||
parser = request.parser; | ||
assert.strictEqual(typeof parser.onIncoming, 'function'); | ||
})); | ||
|
||
request.on('response', common.mustCall((response) => { | ||
response.resume(); | ||
response.on('end', common.mustCall(() => { | ||
assert.strictEqual(parser.onIncoming, null); | ||
})); | ||
})); | ||
})); |