mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -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
+15
-13
@@ -152,11 +152,13 @@ struct StringPtr {
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
|
||||
class Parser : public AsyncWrap, public StreamListener {
|
||||
public:
|
||||
Parser(Environment* env, Local<Object> wrap, parser_type_t type)
|
||||
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_HTTPPARSER),
|
||||
: AsyncWrap(env, wrap,
|
||||
type == HTTP_REQUEST ?
|
||||
AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE :
|
||||
AsyncWrap::PROVIDER_HTTPCLIENTREQUEST),
|
||||
current_buffer_len_(0),
|
||||
current_buffer_data_(nullptr) {
|
||||
Init(type);
|
||||
@@ -503,12 +505,12 @@ class Parser : public AsyncWrap, public StreamListener {
|
||||
}
|
||||
|
||||
|
||||
static void Reinitialize(const FunctionCallbackInfo<Value>& args) {
|
||||
static void Initialize(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
|
||||
CHECK(args[0]->IsInt32());
|
||||
CHECK(args[1]->IsBoolean());
|
||||
bool isReused = args[1]->IsTrue();
|
||||
CHECK(args[1]->IsObject());
|
||||
|
||||
parser_type_t type =
|
||||
static_cast<parser_type_t>(args[0].As<Int32>()->Value());
|
||||
|
||||
@@ -517,16 +519,16 @@ class Parser : public AsyncWrap, public StreamListener {
|
||||
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
|
||||
// Should always be called from the same context.
|
||||
CHECK_EQ(env, parser->env());
|
||||
// This parser has either just been created or it is being reused.
|
||||
// We must only call AsyncReset for the latter case, because AsyncReset has
|
||||
// already been called via the constructor for the former case.
|
||||
if (isReused) {
|
||||
parser->AsyncReset();
|
||||
}
|
||||
|
||||
AsyncWrap::ProviderType provider =
|
||||
(type == HTTP_REQUEST ?
|
||||
AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE
|
||||
: AsyncWrap::PROVIDER_HTTPCLIENTREQUEST);
|
||||
|
||||
parser->set_provider_type(provider);
|
||||
parser->Init(type);
|
||||
}
|
||||
|
||||
|
||||
template <bool should_pause>
|
||||
static void Pause(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
@@ -958,7 +960,7 @@ void InitializeHttpParser(Local<Object> target,
|
||||
env->SetProtoMethod(t, "free", Parser::Free);
|
||||
env->SetProtoMethod(t, "execute", Parser::Execute);
|
||||
env->SetProtoMethod(t, "finish", Parser::Finish);
|
||||
env->SetProtoMethod(t, "reinitialize", Parser::Reinitialize);
|
||||
env->SetProtoMethod(t, "initialize", Parser::Initialize);
|
||||
env->SetProtoMethod(t, "pause", Parser::Pause<true>);
|
||||
env->SetProtoMethod(t, "resume", Parser::Pause<false>);
|
||||
env->SetProtoMethod(t, "consume", Parser::Consume);
|
||||
|
||||
Reference in new issue
Block a user