mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: do not reuse async resource in http parsers
Change resource being used, previously HTTParser was being reused. We are now using IncomingMessage and ClientRequest objects. The goal here is to make the async resource unique for each async operatio Refs: https://github.com/nodejs/node/pull/24330 Refs: https://github.com/nodejs/diagnostics/issues/248 Refs: https://github.com/nodejs/node/pull/21313 Co-authored-by: Matheus Marchini <mat@mmarchini.me> PR-URL: https://github.com/nodejs/node/pull/25094 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
5aaf666b3b
commit
ece507394a
13 files changed
+102
-32
No files matched your search
+1
-2
@@ -632,11 +632,10 @@ function emitFreeNT(socket) {
|
||||
}
|
||||
|
||||
function tickOnSocket(req, socket) {
|
||||
const isParserReused = parsers.hasItems();
|
||||
const parser = parsers.alloc();
|
||||
req.socket = socket;
|
||||
req.connection = socket;
|
||||
parser.reinitialize(HTTPParser.RESPONSE, isParserReused);
|
||||
parser.initialize(HTTPParser.RESPONSE, req);
|
||||
parser.socket = socket;
|
||||
parser.outgoing = req;
|
||||
req.parser = parser;
|
||||
|
||||
+14
-2
@@ -126,6 +126,12 @@ const STATUS_CODES = {
|
||||
|
||||
const kOnExecute = HTTPParser.kOnExecute | 0;
|
||||
|
||||
class HTTPServerAsyncResource {
|
||||
constructor(type, socket) {
|
||||
this.type = type;
|
||||
this.socket = socket;
|
||||
}
|
||||
}
|
||||
|
||||
function ServerResponse(req) {
|
||||
OutgoingMessage.call(this);
|
||||
@@ -349,9 +355,15 @@ function connectionListenerInternal(server, socket) {
|
||||
socket.setTimeout(server.timeout);
|
||||
socket.on('timeout', socketOnTimeout);
|
||||
|
||||
const isParserReused = parsers.hasItems();
|
||||
const parser = parsers.alloc();
|
||||
parser.reinitialize(HTTPParser.REQUEST, isParserReused);
|
||||
|
||||
// TODO(addaleax): This doesn't play well with the
|
||||
// `async_hooks.currentResource()` proposal, see
|
||||
// https://github.com/nodejs/node/pull/21313
|
||||
parser.initialize(
|
||||
HTTPParser.REQUEST,
|
||||
new HTTPServerAsyncResource('HTTPINCOMINGMESSAGE', socket)
|
||||
);
|
||||
parser.socket = socket;
|
||||
|
||||
// We are starting to wait for our headers.
|
||||
|
||||
Reference in new issue
Block a user