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
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
const assert = require('assert');
|
||||
const { createHook } = require('async_hooks');
|
||||
const reused = Symbol('reused');
|
||||
|
||||
let reusedHTTPParser = false;
|
||||
const asyncHook = createHook({
|
||||
init(asyncId, type, triggerAsyncId, resource) {
|
||||
if (resource[reused]) {
|
||||
reusedHTTPParser = true;
|
||||
}
|
||||
resource[reused] = true;
|
||||
}
|
||||
});
|
||||
asyncHook.enable();
|
||||
|
||||
const server = http.createServer(function(req, res) {
|
||||
res.end();
|
||||
});
|
||||
|
||||
const PORT = 3000;
|
||||
const url = 'http://127.0.0.1:' + PORT;
|
||||
|
||||
server.listen(PORT, common.mustCall(() => {
|
||||
http.get(url, common.mustCall(() => {
|
||||
server.close(common.mustCall(() => {
|
||||
server.listen(PORT, common.mustCall(() => {
|
||||
http.get(url, common.mustCall(() => {
|
||||
server.close(common.mustCall(() => {
|
||||
assert.strictEqual(reusedHTTPParser, false);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -21,7 +21,7 @@ const request = Buffer.from(
|
||||
);
|
||||
|
||||
const parser = new HTTPParser(REQUEST);
|
||||
const as = hooks.activitiesOfTypes('HTTPPARSER');
|
||||
const as = hooks.activitiesOfTypes('HTTPINCOMINGMESSAGE');
|
||||
const httpparser = as[0];
|
||||
|
||||
assert.strictEqual(as.length, 1);
|
||||
@@ -47,7 +47,7 @@ process.on('exit', onexit);
|
||||
|
||||
function onexit() {
|
||||
hooks.disable();
|
||||
hooks.sanityCheck('HTTPPARSER');
|
||||
hooks.sanityCheck('HTTPINCOMINGMESSAGE');
|
||||
checkInvocations(httpparser, { init: 1, before: 1, after: 1, destroy: 1 },
|
||||
'when process exits');
|
||||
}
|
||||
@@ -26,7 +26,7 @@ const request = Buffer.from(
|
||||
);
|
||||
|
||||
const parser = new HTTPParser(RESPONSE);
|
||||
const as = hooks.activitiesOfTypes('HTTPPARSER');
|
||||
const as = hooks.activitiesOfTypes('HTTPCLIENTREQUEST');
|
||||
const httpparser = as[0];
|
||||
|
||||
assert.strictEqual(as.length, 1);
|
||||
@@ -58,7 +58,7 @@ process.on('exit', onexit);
|
||||
|
||||
function onexit() {
|
||||
hooks.disable();
|
||||
hooks.sanityCheck('HTTPPARSER');
|
||||
hooks.sanityCheck('HTTPCLIENTREQUEST');
|
||||
checkInvocations(httpparser, { init: 1, before: 2, after: 2, destroy: 1 },
|
||||
'when process exits');
|
||||
}
|
||||
@@ -95,7 +95,7 @@ function expectBody(expected) {
|
||||
throw new Error('hello world');
|
||||
};
|
||||
|
||||
parser.reinitialize(HTTPParser.REQUEST, false);
|
||||
parser.initialize(HTTPParser.REQUEST, request);
|
||||
|
||||
assert.throws(
|
||||
() => { parser.execute(request, 0, request.length); },
|
||||
@@ -555,7 +555,7 @@ function expectBody(expected) {
|
||||
parser[kOnBody] = expectBody('ping');
|
||||
parser.execute(req1, 0, req1.length);
|
||||
|
||||
parser.reinitialize(REQUEST, false);
|
||||
parser.initialize(REQUEST, req2);
|
||||
parser[kOnBody] = expectBody('pong');
|
||||
parser[kOnHeadersComplete] = onHeadersComplete2;
|
||||
parser.execute(req2, 0, req2.length);
|
||||
|
||||
@@ -48,6 +48,8 @@ const { getSystemErrorName } = require('util');
|
||||
if (!common.isMainThread)
|
||||
delete providers.INSPECTORJSBINDING;
|
||||
delete providers.KEYPAIRGENREQUEST;
|
||||
delete providers.HTTPCLIENTREQUEST;
|
||||
delete providers.HTTPINCOMINGMESSAGE;
|
||||
|
||||
const objKeys = Object.keys(providers);
|
||||
if (objKeys.length > 0)
|
||||
|
||||
@@ -7,6 +7,7 @@ const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const httpCommon = require('_http_common');
|
||||
const { HTTPParser } = require('_http_common');
|
||||
const { AsyncResource } = require('async_hooks');
|
||||
const net = require('net');
|
||||
|
||||
const COUNT = httpCommon.parsers.max + 1;
|
||||
@@ -24,7 +25,7 @@ function execAndClose() {
|
||||
process.stdout.write('.');
|
||||
|
||||
const parser = parsers.pop();
|
||||
parser.reinitialize(HTTPParser.RESPONSE, !!parser.reused);
|
||||
parser.initialize(HTTPParser.RESPONSE, new AsyncResource('ClientRequest'));
|
||||
|
||||
const socket = net.connect(common.PORT);
|
||||
socket.on('error', (e) => {
|
||||
|
||||
Reference in new issue
Block a user