forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http_parser: do not dealloc during kOnExecute
`freeParser` deallocates `Parser` instances early if they do not fit into the free list. This does not play well with recent socket consumption change, because it will try to deallocate the parser while executing on its stack. Regression was introduced in: 1bc4468 Fix: nodejs#2928 PR-URL: nodejs#2956 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
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,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const httpCommon = require('_http_common'); | ||
const HTTPParser = process.binding('http_parser').HTTPParser; | ||
const net = require('net'); | ||
|
||
const PARALLEL = 30; | ||
const COUNT = httpCommon.parsers.max + 100; | ||
|
||
const parsers = new Array(COUNT); | ||
for (var i = 0; i < parsers.length; i++) | ||
parsers[i] = httpCommon.parsers.alloc(); | ||
|
||
var gotRequests = 0; | ||
var gotResponses = 0; | ||
|
||
function execAndClose() { | ||
process.stdout.write('.'); | ||
if (parsers.length === 0) | ||
return; | ||
|
||
const parser = parsers.pop(); | ||
parser.reinitialize(HTTPParser.RESPONSE); | ||
const socket = net.connect(common.PORT); | ||
parser.consume(socket._handle._externalStream); | ||
|
||
parser.onIncoming = function onIncoming() { | ||
process.stdout.write('+'); | ||
gotResponses++; | ||
parser.unconsume(socket._handle._externalStream); | ||
httpCommon.freeParser(parser); | ||
socket.destroy(); | ||
setImmediate(execAndClose); | ||
}; | ||
} | ||
|
||
var server = net.createServer(function(c) { | ||
if (++gotRequests === COUNT) | ||
server.close(); | ||
c.end('HTTP/1.1 200 OK\r\n\r\n', function() { | ||
c.destroySoon(); | ||
}); | ||
}).listen(common.PORT, function() { | ||
for (var i = 0; i < PARALLEL; i++) | ||
execAndClose(); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.equal(gotResponses, COUNT); | ||
}); |