-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
http_parser: do not dealloc during kOnExecute #2956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nvm. It may not work here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... Let's leave it as it is. |
||
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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to have a
const
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that
delete
may be called onconst
pointer... Am I wrong?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@indutny I just tried this
with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Wall
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@indutny Hmmm, I tried that now. No warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think you're right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, I'm changing the refcount of the parser, so it won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@indutny Ah, right. Sorry for the fuss.